summaryrefslogtreecommitdiff
path: root/builtin-merge.c
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2008-10-03 12:04:47 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2008-10-03 15:18:45 (GMT)
commitcf10f9fdd5e673a163847f0e931ce9731507e03b (patch)
tree16f66fce8188e900ae2c995ea62412e8671a3dd7 /builtin-merge.c
parent52e8370bc7a71366b664ece0a9ec0b79d673a356 (diff)
downloadgit-cf10f9fdd5e673a163847f0e931ce9731507e03b.zip
git-cf10f9fdd5e673a163847f0e931ce9731507e03b.tar.gz
git-cf10f9fdd5e673a163847f0e931ce9731507e03b.tar.bz2
builtin-commit: use reduce_heads() only when appropriate
Since commit 6bb6b034 (builtin-commit: use commit_tree(), 2008-09-10), builtin-commit performs a reduce_heads() unconditionally. However, it's not always needed, and in some cases even harmful. reduce_heads() is not needed for the initial commit or for an "ordinary" commit, because they don't have any or have only one parent, respectively. reduce_heads() must be avoided when 'git commit' is run after a 'git merge --no-ff --no-commit', otherwise it will turn the non-fast-forward merge into fast-forward. For the same reason, reduce_heads() must be avoided when amending such a merge commit. To resolve this issue, 'git merge' will write info about whether fast-forward is allowed or not to $GIT_DIR/MERGE_MODE. Based on this info, 'git commit' will only perform reduce_heads() when it's committing a merge and fast-forward is enabled. Also add test cases to ensure that non-fast-forward merges are committed and amended properly. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'builtin-merge.c')
-rw-r--r--builtin-merge.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin-merge.c b/builtin-merge.c
index 5c65a58..4c9ed5d 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -180,6 +180,7 @@ static void drop_save(void)
{
unlink(git_path("MERGE_HEAD"));
unlink(git_path("MERGE_MSG"));
+ unlink(git_path("MERGE_MODE"));
}
static void save_state(void)
@@ -1210,6 +1211,15 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
merge_msg.len)
die("Could not write to %s", git_path("MERGE_MSG"));
close(fd);
+ fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0)
+ die("Could open %s for writing", git_path("MERGE_MODE"));
+ strbuf_reset(&buf);
+ if (!allow_fast_forward)
+ strbuf_addf(&buf, "no-ff");
+ if (write_in_full(fd, buf.buf, buf.len) != buf.len)
+ die("Could not write to %s", git_path("MERGE_MODE"));
+ close(fd);
}
if (merge_was_ok) {