]>
Commit | Line | Data |
---|---|---|
bebdbcd4 RB |
1 | #include "clar_libgit2.h" |
2 | #include "checkout_helpers.h" | |
3 | #include "refs.h" | |
22a2d3d5 | 4 | #include "futils.h" |
e44abe16 | 5 | #include "index.h" |
bebdbcd4 | 6 | |
bebdbcd4 RB |
7 | void assert_on_branch(git_repository *repo, const char *branch) |
8 | { | |
9 | git_reference *head; | |
e579e0f7 | 10 | git_str bname = GIT_STR_INIT; |
bebdbcd4 RB |
11 | |
12 | cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); | |
ac3d33df | 13 | cl_assert_(git_reference_type(head) == GIT_REFERENCE_SYMBOLIC, branch); |
bebdbcd4 | 14 | |
e579e0f7 | 15 | cl_git_pass(git_str_joinpath(&bname, "refs/heads", branch)); |
bebdbcd4 RB |
16 | cl_assert_equal_s(bname.ptr, git_reference_symbolic_target(head)); |
17 | ||
18 | git_reference_free(head); | |
e579e0f7 | 19 | git_str_dispose(&bname); |
bebdbcd4 RB |
20 | } |
21 | ||
22 | void reset_index_to_treeish(git_object *treeish) | |
23 | { | |
24 | git_object *tree; | |
25 | git_index *index; | |
26 | git_repository *repo = git_object_owner(treeish); | |
27 | ||
ac3d33df | 28 | cl_git_pass(git_object_peel(&tree, treeish, GIT_OBJECT_TREE)); |
bebdbcd4 RB |
29 | |
30 | cl_git_pass(git_repository_index(&index, repo)); | |
31 | cl_git_pass(git_index_read_tree(index, (git_tree *)tree)); | |
32 | cl_git_pass(git_index_write(index)); | |
33 | ||
34 | git_object_free(tree); | |
35 | git_index_free(index); | |
36 | } | |
37 | ||
36fd9e30 RB |
38 | int checkout_count_callback( |
39 | git_checkout_notify_t why, | |
40 | const char *path, | |
41 | const git_diff_file *baseline, | |
42 | const git_diff_file *target, | |
43 | const git_diff_file *workdir, | |
44 | void *payload) | |
45 | { | |
46 | checkout_counts *ct = payload; | |
47 | ||
48 | GIT_UNUSED(baseline); GIT_UNUSED(target); GIT_UNUSED(workdir); | |
49 | ||
50 | if (why & GIT_CHECKOUT_NOTIFY_CONFLICT) { | |
51 | ct->n_conflicts++; | |
52 | ||
53 | if (ct->debug) { | |
54 | if (workdir) { | |
55 | if (baseline) { | |
56 | if (target) | |
57 | fprintf(stderr, "M %s (conflicts with M %s)\n", | |
58 | workdir->path, target->path); | |
59 | else | |
60 | fprintf(stderr, "M %s (conflicts with D %s)\n", | |
61 | workdir->path, baseline->path); | |
62 | } else { | |
63 | if (target) | |
64 | fprintf(stderr, "Existing %s (conflicts with A %s)\n", | |
65 | workdir->path, target->path); | |
66 | else | |
67 | fprintf(stderr, "How can an untracked file be a conflict (%s)\n", workdir->path); | |
68 | } | |
69 | } else { | |
70 | if (baseline) { | |
71 | if (target) | |
72 | fprintf(stderr, "D %s (conflicts with M %s)\n", | |
73 | target->path, baseline->path); | |
74 | else | |
75 | fprintf(stderr, "D %s (conflicts with D %s)\n", | |
76 | baseline->path, baseline->path); | |
77 | } else { | |
78 | if (target) | |
79 | fprintf(stderr, "How can an added file with no workdir be a conflict (%s)\n", target->path); | |
80 | else | |
81 | fprintf(stderr, "How can a nonexistent file be a conflict (%s)\n", path); | |
82 | } | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | if (why & GIT_CHECKOUT_NOTIFY_DIRTY) { | |
88 | ct->n_dirty++; | |
89 | ||
90 | if (ct->debug) { | |
91 | if (workdir) | |
92 | fprintf(stderr, "M %s\n", workdir->path); | |
93 | else | |
94 | fprintf(stderr, "D %s\n", baseline->path); | |
95 | } | |
96 | } | |
97 | ||
98 | if (why & GIT_CHECKOUT_NOTIFY_UPDATED) { | |
99 | ct->n_updates++; | |
100 | ||
101 | if (ct->debug) { | |
102 | if (baseline) { | |
103 | if (target) | |
104 | fprintf(stderr, "update: M %s\n", path); | |
105 | else | |
106 | fprintf(stderr, "update: D %s\n", path); | |
107 | } else { | |
108 | if (target) | |
109 | fprintf(stderr, "update: A %s\n", path); | |
110 | else | |
111 | fprintf(stderr, "update: this makes no sense %s\n", path); | |
112 | } | |
113 | } | |
114 | } | |
115 | ||
116 | if (why & GIT_CHECKOUT_NOTIFY_UNTRACKED) { | |
117 | ct->n_untracked++; | |
118 | ||
119 | if (ct->debug) | |
120 | fprintf(stderr, "? %s\n", path); | |
121 | } | |
122 | ||
123 | if (why & GIT_CHECKOUT_NOTIFY_IGNORED) { | |
124 | ct->n_ignored++; | |
125 | ||
126 | if (ct->debug) | |
127 | fprintf(stderr, "I %s\n", path); | |
128 | } | |
129 | ||
130 | return 0; | |
131 | } | |
e44abe16 CMN |
132 | |
133 | void tick_index(git_index *index) | |
134 | { | |
0226f7dd | 135 | struct timespec ts; |
35439f59 | 136 | struct p_timeval times[2]; |
e44abe16 CMN |
137 | |
138 | cl_assert(index->on_disk); | |
139 | cl_assert(git_index_path(index)); | |
140 | ||
141 | cl_git_pass(git_index_read(index, true)); | |
142 | ts = index->stamp.mtime; | |
143 | ||
0226f7dd AR |
144 | times[0].tv_sec = ts.tv_sec; |
145 | times[0].tv_usec = ts.tv_nsec / 1000; | |
146 | times[1].tv_sec = ts.tv_sec + 5; | |
147 | times[1].tv_usec = ts.tv_nsec / 1000; | |
121c3171 ET |
148 | |
149 | cl_git_pass(p_utimes(git_index_path(index), times)); | |
e44abe16 CMN |
150 | cl_git_pass(git_index_read(index, true)); |
151 | } |