git-merge-ours: make it a builtin.
Except that this fixes a longstanding corner case bug by tightening the way underlying diff-index command is run, it is functionally equivalent to the scripted version. Signed-off-by: Thomas Harning Jr <harningt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Harning committed
Nov 22, 2007 at 15:19 UTC
a00a42ae33708caa742d9e9fbf10692cfa42f032
5 files changed
+32
-1
Makefile
+2
-1
@@ -221,7 +221,7 @@ SCRIPT_SH = \
221
git-sh-setup.sh \
222
git-am.sh \
223
git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
224
- git-merge-resolve.sh git-merge-ours.sh \
224
+ git-merge-resolve.sh \
225
git-lost-found.sh git-quiltimport.sh git-submodule.sh \
226
git-filter-branch.sh \
227
git-stash.sh
@@ -353,6 +353,7 @@ BUILTIN_OBJS = \
353
builtin-mailsplit.o \
354
builtin-merge-base.o \
355
builtin-merge-file.o \
356
+ builtin-merge-ours.o \
357
builtin-mv.o \
358
builtin-name-rev.o \
359
builtin-pack-objects.o \
builtin-merge-ours.c
new
+28
@@ -0,0 +1,28 @@
1
+/*
2
+ * Implementation of git-merge-ours.sh as builtin
3
+ *
4
+ * Copyright (c) 2007 Thomas Harning Jr
5
+ * Original:
6
+ * Original Copyright (c) 2005 Junio C Hamano
7
+ *
8
+ * Pretend we resolved the heads, but declare our tree trumps everybody else.
9
+ */
10
+#include "git-compat-util.h"
11
+#include "builtin.h"
12
+
13
+static const char *diff_index_args[] = {
14
+ "diff-index", "--quiet", "--cached", "HEAD", "--", NULL
15
+};
16
+#define NARGS (ARRAY_SIZE(diff_index_args) - 1)
17
+
18
+int cmd_merge_ours(int argc, const char **argv, const char *prefix)
19
+{
20
+ /*
21
+ * We need to exit with 2 if the index does not match our HEAD tree,
22
+ * because the current index is what we will be committing as the
23
+ * merge result.
24
+ */
25
+ if (cmd_diff_index(NARGS, diff_index_args, prefix))
26
+ exit(2);
27
+ exit(0);
28
+}
builtin.h
+1
@@ -51,6 +51,7 @@ extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
51
extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
52
extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
53
extern int cmd_merge_base(int argc, const char **argv, const char *prefix);
54
+extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);
55
extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
56
extern int cmd_mv(int argc, const char **argv, const char *prefix);
57
extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
contrib/examples/git-merge-ours.sh
renamed
git.c
+1
@@ -325,6 +325,7 @@ static void handle_internal_command(int argc, const char **argv)
325
{ "mailsplit", cmd_mailsplit },
326
{ "merge-base", cmd_merge_base, RUN_SETUP },
327
{ "merge-file", cmd_merge_file },
328
+ { "merge-ours", cmd_merge_ours, RUN_SETUP },
329
{ "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
330
{ "name-rev", cmd_name_rev, RUN_SETUP },
331
{ "pack-objects", cmd_pack_objects, RUN_SETUP },