8000 Bindings/libgit2sharp/020 2 by grossvin22 · Pull Request #3337 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Bindings/libgit2sharp/020 2 #3337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Introduce test for checkout case-changing rename
  • Loading branch information
Edward Thomson committed Jan 19, 2015
commit e7f5425b79ea0410edb7f9199231b7795b714535
< 8000 div id="files" class="diff-view js-diff-container" data-hpc>
76 changes: 76 additions & 0 deletions tests/checkout/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,79 @@ void test_checkout_tree__filemode_preserved_in_index(void)
git_index_free(index);
}

void test_checkout_tree__case_changing_rename(void)
{
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_oid master_id, dir_commit_id, tree_id, commit_id;
git_commit *master_commit, *dir_commit;
git_tree *tree;
git_signature *signature;
const git_index_entry *index_entry;
bool case_sensitive;

assert_on_branch(g_repo, "master");

cl_git_pass(git_repository_index(&index, g_repo));

/* Switch branches and perform a case-changing rename */

opts.checkout_strategy = GIT_CHECKOUT_FORCE;

cl_git_pass(git_reference_name_to_id(&dir_commit_id, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&dir_commit, g_repo, &dir_commit_id));

cl_git_pass(git_checkout_tree(g_repo, (git_object *)dir_commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL, NULL));

cl_assert(git_path_isfile("testrepo/README"));
case_sensitive = !git_path_isfile("testrepo/readme");

cl_assert(index_entry = git_index_get_bypath(index, "README", 0));
cl_assert_equal_s("README", index_entry->path);

cl_git_pass(git_index_remove_bypath(index, "README"));
cl_git_pass(p_rename("testrepo/README", "testrepo/__readme__"));
cl_git_pass(p_rename("testrepo/__readme__", "testrepo/readme"));
cl_git_append2file("testrepo/readme", "An addendum...");
cl_git_pass(git_index_add_bypath(index, "readme"));

cl_git_pass(git_index_write(index));

cl_git_pass(git_index_write_tree(&tree_id, index));
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));

cl_git_pass(git_signature_new(&signature, "Renamer", "rename@contoso.com", time(NULL), 0));

cl_git_pass(git_commit_create(&commit_id, g_repo, "refs/heads/dir", signature, signature, NULL, "case-changing rename", tree, 1, (const git_commit **)&dir_commit));

cl_assert(git_path_isfile("testrepo/readme"));
if (case_sensitive)
cl_assert(!git_path_isfile("testrepo/README"));

cl_assert(index_entry = git_index_get_bypath(index, "readme", 0));
cl_assert_equal_s("readme", index_entry->path);

/* Switching back to master should rename readme -> README */
opts.checkout_strategy = GIT_CHECKOUT_SAFE;

cl_git_pass(git_reference_name_to_id(&master_id, g_repo, "refs/heads/master"));
cl_git_pass(git_commit_lookup(&master_commit, g_repo, &master_id));

cl_git_pass(git_checkout_tree(g_repo, (git_object *)master_commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL, NULL));

assert_on_branch(g_repo, "master");

cl_assert(git_path_isfile("testrepo/README"));
if (case_sensitive)
cl_assert(!git_path_isfile("testrepo/readme"));

cl_assert(index_entry = git_index_get_bypath(index, "README", 0));
cl_assert_equal_s("README", index_entry->path);

git_signature_free(signature);
git_tree_free(tree);
git_commit_free(dir_commit);
git_commit_free(master_commit);
}
0