merge-ours: do not use cmd_*() as a subroutine
The call to cmd_diff_index() "git merge-ours" makes has been working by accident that the function did not call exit(3), and the caller exited almost immediately after making a call, but it sets a bad precedent for people to cut and paste. For finding out if the index exactly matches the HEAD (or a given tree-ish), there is index_differs_from() which is exactly written for that purpose. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 10, 2017 at 12:04 UTC
a92b1095d190ea348d365baeb9ff5c5023d0efd2
1 file changed
+7
-9
builtin/merge-ours.c
+7
-9
@@ -9,26 +9,24 @@
9
*/
10
#include "git-compat-util.h"
11
#include "builtin.h"
12
+#include "diff.h"
13
14
static const char builtin_merge_ours_usage[] =
15
"git merge-ours <base>... -- HEAD <remote>...";
16
16
-static const char *diff_index_args[] = {
17
- "diff-index", "--quiet", "--cached", "HEAD", "--", NULL
18
-};
19
-#define NARGS (ARRAY_SIZE(diff_index_args) - 1)
20
-
17
int cmd_merge_ours(int argc, const char **argv, const char *prefix)
18
{
19
if (argc == 2 && !strcmp(argv[1], "-h"))
20
usage(builtin_merge_ours_usage);
21
22
/*
27
- * We need to exit with 2 if the index does not match our HEAD tree,
28
- * because the current index is what we will be committing as the
29
- * merge result.
23
+ * The contents of the current index becomes the tree we
24
+ * commit. The index must match HEAD, or this merge cannot go
25
+ * through.
26
*/
31
- if (cmd_diff_index(NARGS, diff_index_args, prefix))
27
+ if (read_cache() < 0)
28
+ die_errno("read_cache failed");
29
+ if (index_differs_from("HEAD", 0, 0))
30
exit(2);
31
exit(0);
32
}