summaryrefslogtreecommitdiff
path: root/builtin/merge.c
diff options
context:
space:
mode:
authorLibravatar Clemens Buchacher <drizzd@aon.at>2010-11-14 23:07:49 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-11-15 09:27:33 -0800
commit172b6428d06ff4eb0812f087a497d50b6c878fe1 (patch)
tree0d5dd95e7f771f95692673b0a6d5d853ecae48a5 /builtin/merge.c
parenttest-lib: user-friendly alternatives to test [-d|-f|-e] (diff)
downloadtgif-172b6428d06ff4eb0812f087a497d50b6c878fe1.tar.xz
do not overwrite untracked during merge from unborn branch
In case HEAD does not point to a valid commit yet, merge is implemented as a hard reset. This will cause untracked files to be overwritten. Instead, assume the empty tree for HEAD and do a regular merge. An untracked file will cause the merge to abort and do nothing. If no conflicting files are present, the merge will have the same effect as a hard reset. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge.c')
-rw-r--r--builtin/merge.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 37ce4f589f..2a6c49f6ce 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -231,6 +231,24 @@ static void save_state(void)
die("not a valid object: %s", buffer.buf);
}
+static void read_empty(unsigned const char *sha1, int verbose)
+{
+ int i = 0;
+ const char *args[7];
+
+ args[i++] = "read-tree";
+ if (verbose)
+ args[i++] = "-v";
+ args[i++] = "-m";
+ args[i++] = "-u";
+ args[i++] = EMPTY_TREE_SHA1_HEX;
+ args[i++] = sha1_to_hex(sha1);
+ args[i] = NULL;
+
+ if (run_command_v_opt(args, RUN_GIT_CMD))
+ die("read-tree failed");
+}
+
static void reset_hard(unsigned const char *sha1, int verbose)
{
int i = 0;
@@ -979,7 +997,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
die("%s - not something we can merge", argv[0]);
update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
DIE_ON_ERR);
- reset_hard(remote_head->sha1, 0);
+ read_empty(remote_head->sha1, 0);
return 0;
} else {
struct strbuf merge_names = STRBUF_INIT;