]>
git.proxmox.com Git - libgit2.git/blob - tests/index/rename.c
1 #include "clar_libgit2.h"
4 void test_index_rename__single_file(void)
10 const git_index_entry
*entry
;
12 p_mkdir("rename", 0700);
14 cl_git_pass(git_repository_init(&repo
, "./rename", 0));
15 cl_git_pass(git_repository_index(&index
, repo
));
17 cl_assert(git_index_entrycount(index
) == 0);
19 cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
21 /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
22 cl_git_pass(git_index_add_bypath(index
, "lame.name.txt"));
23 cl_assert(git_index_entrycount(index
) == 1);
25 cl_git_pass(git_oid_fromstr(&expected
, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));
27 cl_assert(!git_index_find(&position
, index
, "lame.name.txt"));
29 entry
= git_index_get_byindex(index
, position
);
30 cl_assert_equal_oid(&expected
, &entry
->id
);
32 /* This removes the entry from the index, but not from the object database */
33 cl_git_pass(git_index_remove(index
, "lame.name.txt", 0));
34 cl_assert(git_index_entrycount(index
) == 0);
36 p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");
38 cl_git_pass(git_index_add_bypath(index
, "fancy.name.txt"));
39 cl_assert(git_index_entrycount(index
) == 1);
41 cl_assert(!git_index_find(&position
, index
, "fancy.name.txt"));
43 entry
= git_index_get_byindex(index
, position
);
44 cl_assert_equal_oid(&expected
, &entry
->id
);
46 git_index_free(index
);
47 git_repository_free(repo
);
49 cl_fixture_cleanup("rename");
52 void test_index_rename__casechanging(void)
56 const git_index_entry
*entry
;
57 git_index_entry
new = {{0}};
59 p_mkdir("rename", 0700);
61 cl_git_pass(git_repository_init(&repo
, "./rename", 0));
62 cl_git_pass(git_repository_index(&index
, repo
));
64 cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
66 cl_git_pass(git_index_add_bypath(index
, "lame.name.txt"));
67 cl_assert_equal_i(1, git_index_entrycount(index
));
68 cl_assert((entry
= git_index_get_bypath(index
, "lame.name.txt", 0)));
70 memcpy(&new, entry
, sizeof(git_index_entry
));
71 new.path
= "LAME.name.TXT";
73 cl_git_pass(git_index_add(index
, &new));
74 cl_assert((entry
= git_index_get_bypath(index
, "LAME.name.TXT", 0)));
76 if (cl_repo_get_bool(repo
, "core.ignorecase"))
77 cl_assert_equal_i(1, git_index_entrycount(index
));
79 cl_assert_equal_i(2, git_index_entrycount(index
));
81 git_index_free(index
);
82 git_repository_free(repo
);
84 cl_fixture_cleanup("rename");