]>
Commit | Line | Data |
---|---|---|
99a09f7f ET |
1 | #include "clar_libgit2.h" |
2 | #include "index.h" | |
3 | #include "git2/sys/index.h" | |
4 | #include "git2/repository.h" | |
5 | #include "../reset/reset_helpers.h" | |
6 | ||
7 | static git_repository *repo; | |
8 | static git_index *repo_index; | |
9 | ||
10 | #define TEST_REPO_PATH "nsecs" | |
11 | ||
12 | // Fixture setup and teardown | |
13 | void test_index_nsec__initialize(void) | |
14 | { | |
15 | repo = cl_git_sandbox_init("nsecs"); | |
16 | git_repository_index(&repo_index, repo); | |
17 | } | |
18 | ||
19 | void test_index_nsec__cleanup(void) | |
20 | { | |
21 | git_index_free(repo_index); | |
22 | repo_index = NULL; | |
23 | ||
24 | cl_git_sandbox_cleanup(); | |
25 | } | |
26 | ||
27 | static bool has_nsecs(void) | |
28 | { | |
29 | const git_index_entry *entry; | |
30 | size_t i; | |
31 | bool has_nsecs = false; | |
32 | ||
33 | for (i = 0; i < git_index_entrycount(repo_index); i++) { | |
34 | entry = git_index_get_byindex(repo_index, i); | |
35 | ||
36 | if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) { | |
37 | has_nsecs = true; | |
38 | break; | |
39 | } | |
40 | } | |
41 | ||
42 | return has_nsecs; | |
43 | } | |
44 | ||
45 | void test_index_nsec__has_nanos(void) | |
46 | { | |
47 | cl_assert_equal_b(true, has_nsecs()); | |
48 | } | |
49 | ||
50 | void test_index_nsec__staging_maintains_other_nanos(void) | |
51 | { | |
52 | const git_index_entry *entry; | |
53 | ||
54 | cl_git_rewritefile("nsecs/a.txt", "This is file A"); | |
55 | cl_git_pass(git_index_add_bypath(repo_index, "a.txt")); | |
56 | cl_git_pass(git_index_write(repo_index)); | |
57 | ||
58 | cl_git_pass(git_index_write(repo_index)); | |
59 | ||
60 | git_index_read(repo_index, 1); | |
61 | cl_assert_equal_b(true, has_nsecs()); | |
62 | ||
63 | cl_assert((entry = git_index_get_bypath(repo_index, "a.txt", 0))); | |
64 | cl_assert_equal_i(0, entry->ctime.nanoseconds); | |
65 | cl_assert_equal_i(0, entry->mtime.nanoseconds); | |
66 | } | |
67 | ||
68 | void test_index_nsec__status_doesnt_clear_nsecs(void) | |
69 | { | |
70 | git_status_list *statuslist; | |
71 | ||
72 | cl_git_pass(git_status_list_new(&statuslist, repo, NULL)); | |
73 | ||
74 | git_index_read(repo_index, 1); | |
75 | cl_assert_equal_b(true, has_nsecs()); | |
76 | ||
77 | git_status_list_free(statuslist); | |
78 | } |