1 #include "clar_libgit2.h"
2 #include "checkout_helpers.h"
7 void assert_on_branch(git_repository
*repo
, const char *branch
)
10 git_buf bname
= GIT_BUF_INIT
;
12 cl_git_pass(git_reference_lookup(&head
, repo
, GIT_HEAD_FILE
));
13 cl_assert_(git_reference_type(head
) == GIT_REFERENCE_SYMBOLIC
, branch
);
15 cl_git_pass(git_buf_joinpath(&bname
, "refs/heads", branch
));
16 cl_assert_equal_s(bname
.ptr
, git_reference_symbolic_target(head
));
18 git_reference_free(head
);
19 git_buf_dispose(&bname
);
22 void reset_index_to_treeish(git_object
*treeish
)
26 git_repository
*repo
= git_object_owner(treeish
);
28 cl_git_pass(git_object_peel(&tree
, treeish
, GIT_OBJECT_TREE
));
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
));
34 git_object_free(tree
);
35 git_index_free(index
);
38 int checkout_count_callback(
39 git_checkout_notify_t why
,
41 const git_diff_file
*baseline
,
42 const git_diff_file
*target
,
43 const git_diff_file
*workdir
,
46 checkout_counts
*ct
= payload
;
48 GIT_UNUSED(baseline
); GIT_UNUSED(target
); GIT_UNUSED(workdir
);
50 if (why
& GIT_CHECKOUT_NOTIFY_CONFLICT
) {
57 fprintf(stderr
, "M %s (conflicts with M %s)\n",
58 workdir
->path
, target
->path
);
60 fprintf(stderr
, "M %s (conflicts with D %s)\n",
61 workdir
->path
, baseline
->path
);
64 fprintf(stderr
, "Existing %s (conflicts with A %s)\n",
65 workdir
->path
, target
->path
);
67 fprintf(stderr
, "How can an untracked file be a conflict (%s)\n", workdir
->path
);
72 fprintf(stderr
, "D %s (conflicts with M %s)\n",
73 target
->path
, baseline
->path
);
75 fprintf(stderr
, "D %s (conflicts with D %s)\n",
76 baseline
->path
, baseline
->path
);
79 fprintf(stderr
, "How can an added file with no workdir be a conflict (%s)\n", target
->path
);
81 fprintf(stderr
, "How can a nonexistent file be a conflict (%s)\n", path
);
87 if (why
& GIT_CHECKOUT_NOTIFY_DIRTY
) {
92 fprintf(stderr
, "M %s\n", workdir
->path
);
94 fprintf(stderr
, "D %s\n", baseline
->path
);
98 if (why
& GIT_CHECKOUT_NOTIFY_UPDATED
) {
104 fprintf(stderr
, "update: M %s\n", path
);
106 fprintf(stderr
, "update: D %s\n", path
);
109 fprintf(stderr
, "update: A %s\n", path
);
111 fprintf(stderr
, "update: this makes no sense %s\n", path
);
116 if (why
& GIT_CHECKOUT_NOTIFY_UNTRACKED
) {
120 fprintf(stderr
, "? %s\n", path
);
123 if (why
& GIT_CHECKOUT_NOTIFY_IGNORED
) {
127 fprintf(stderr
, "I %s\n", path
);
133 void tick_index(git_index
*index
)
136 struct p_timeval times
[2];
138 cl_assert(index
->on_disk
);
139 cl_assert(git_index_path(index
));
141 cl_git_pass(git_index_read(index
, true));
142 ts
= index
->stamp
.mtime
;
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;
149 cl_git_pass(p_utimes(git_index_path(index
), times
));
150 cl_git_pass(git_index_read(index
, true));