]>
Commit | Line | Data |
---|---|---|
f45ec1a0 ET |
1 | #include "clar_libgit2.h" |
2 | #include "index.h" | |
3 | #include "git2/repository.h" | |
4 | ||
5 | static git_repository *repo; | |
6 | static git_index *repo_index; | |
7 | ||
8 | #define TEST_REPO_PATH "mergedrepo" | |
9 | #define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index" | |
10 | ||
11 | // Fixture setup and teardown | |
12 | void test_index_stage__initialize(void) | |
13 | { | |
14 | repo = cl_git_sandbox_init("mergedrepo"); | |
15 | git_repository_index(&repo_index, repo); | |
16 | } | |
17 | ||
18 | void test_index_stage__cleanup(void) | |
19 | { | |
20 | git_index_free(repo_index); | |
9094d30b SC |
21 | repo_index = NULL; |
22 | ||
f45ec1a0 ET |
23 | cl_git_sandbox_cleanup(); |
24 | } | |
25 | ||
26 | ||
27 | void test_index_stage__add_always_adds_stage_0(void) | |
28 | { | |
11d9f6b3 | 29 | size_t entry_idx; |
f45d51ff | 30 | const git_index_entry *entry; |
f45ec1a0 ET |
31 | |
32 | cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n"); | |
33 | ||
25743bd7 | 34 | cl_git_pass(git_index_add_bypath(repo_index, "new-file.txt")); |
f45ec1a0 | 35 | |
11d9f6b3 | 36 | cl_assert(!git_index_find(&entry_idx, repo_index, "new-file.txt")); |
f45ec1a0 ET |
37 | cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL); |
38 | cl_assert(git_index_entry_stage(entry) == 0); | |
39 | } | |
40 | ||
41 | void test_index_stage__find_gets_first_stage(void) | |
42 | { | |
11d9f6b3 | 43 | size_t entry_idx; |
f45d51ff | 44 | const git_index_entry *entry; |
f45ec1a0 | 45 | |
11d9f6b3 | 46 | cl_assert(!git_index_find(&entry_idx, repo_index, "one.txt")); |
f45ec1a0 ET |
47 | cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL); |
48 | cl_assert(git_index_entry_stage(entry) == 0); | |
49 | ||
11d9f6b3 | 50 | cl_assert(!git_index_find(&entry_idx, repo_index, "two.txt")); |
f45ec1a0 ET |
51 | cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL); |
52 | cl_assert(git_index_entry_stage(entry) == 0); | |
53 | ||
11d9f6b3 | 54 | cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-one.txt")); |
f45ec1a0 ET |
55 | cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL); |
56 | cl_assert(git_index_entry_stage(entry) == 1); | |
57 | ||
11d9f6b3 | 58 | cl_assert(!git_index_find(&entry_idx, repo_index, "conflicts-two.txt")); |
f45ec1a0 ET |
59 | cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL); |
60 | cl_assert(git_index_entry_stage(entry) == 1); | |
61 | } | |
62 |