]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
c515b5bf CMN |
2 | #include "posix.h" |
3 | ||
c515b5bf CMN |
4 | void test_index_rename__single_file(void) |
5 | { | |
6 | git_repository *repo; | |
7 | git_index *index; | |
11d9f6b3 | 8 | size_t position; |
c515b5bf | 9 | git_oid expected; |
f45d51ff | 10 | const git_index_entry *entry; |
c515b5bf CMN |
11 | |
12 | p_mkdir("rename", 0700); | |
13 | ||
14 | cl_git_pass(git_repository_init(&repo, "./rename", 0)); | |
15 | cl_git_pass(git_repository_index(&index, repo)); | |
16 | ||
17 | cl_assert(git_index_entrycount(index) == 0); | |
18 | ||
1d415455 | 19 | cl_git_mkfile("./rename/lame.name.txt", "new_file\n"); |
c515b5bf CMN |
20 | |
21 | /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */ | |
25743bd7 | 22 | cl_git_pass(git_index_add_bypath(index, "lame.name.txt")); |
c515b5bf CMN |
23 | cl_assert(git_index_entrycount(index) == 1); |
24 | ||
25 | cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); | |
26 | ||
11d9f6b3 | 27 | cl_assert(!git_index_find(&position, index, "lame.name.txt")); |
c515b5bf | 28 | |
f45ec1a0 | 29 | entry = git_index_get_byindex(index, position); |
d541170c | 30 | cl_assert(git_oid_cmp(&expected, &entry->id) == 0); |
c515b5bf CMN |
31 | |
32 | /* This removes the entry from the index, but not from the object database */ | |
f45ec1a0 | 33 | cl_git_pass(git_index_remove(index, "lame.name.txt", 0)); |
c515b5bf CMN |
34 | cl_assert(git_index_entrycount(index) == 0); |
35 | ||
36 | p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); | |
37 | ||
25743bd7 | 38 | cl_git_pass(git_index_add_bypath(index, "fancy.name.txt")); |
c515b5bf CMN |
39 | cl_assert(git_index_entrycount(index) == 1); |
40 | ||
11d9f6b3 | 41 | cl_assert(!git_index_find(&position, index, "fancy.name.txt")); |
c515b5bf | 42 | |
f45ec1a0 | 43 | entry = git_index_get_byindex(index, position); |
d541170c | 44 | cl_assert(git_oid_cmp(&expected, &entry->id) == 0); |
c515b5bf CMN |
45 | |
46 | git_index_free(index); | |
47 | git_repository_free(repo); | |
48 | ||
49 | cl_fixture_cleanup("rename"); | |
50 | } |