]> git.proxmox.com Git - libgit2.git/blame - tests/index/rename.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / index / rename.c
CommitLineData
3fd1520c 1#include "clar_libgit2.h"
c515b5bf
CMN
2#include "posix.h"
3
c515b5bf
CMN
4void 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);
0cee70eb 30 cl_assert_equal_oid(&expected, &entry->id);
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);
0cee70eb 44 cl_assert_equal_oid(&expected, &entry->id);
c515b5bf
CMN
45
46 git_index_free(index);
47 git_repository_free(repo);
48
49 cl_fixture_cleanup("rename");
50}
a32bc85e
ET
51
52void test_index_rename__casechanging(void)
53{
54 git_repository *repo;
55 git_index *index;
56 const git_index_entry *entry;
57 git_index_entry new = {{0}};
58
59 p_mkdir("rename", 0700);
60
61 cl_git_pass(git_repository_init(&repo, "./rename", 0));
62 cl_git_pass(git_repository_index(&index, repo));
63
64 cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
65
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)));
69
70 memcpy(&new, entry, sizeof(git_index_entry));
71 new.path = "LAME.name.TXT";
72
73 cl_git_pass(git_index_add(index, &new));
74 cl_assert((entry = git_index_get_bypath(index, "LAME.name.TXT", 0)));
75
76 if (cl_repo_get_bool(repo, "core.ignorecase"))
77 cl_assert_equal_i(1, git_index_entrycount(index));
78 else
79 cl_assert_equal_i(2, git_index_entrycount(index));
5c5df666
CMN
80
81 git_index_free(index);
82 git_repository_free(repo);
83
84 cl_fixture_cleanup("rename");
a32bc85e
ET
85}
86