In case git merge --no-ff is used with --no-commit or we have a conflict, write info about if fast forwards are allowed or not to $GIT_DIR/MERGE_MODE. Based on this info, don't run reduce_heads() in case fast-forwards are denied, to avoid turning a 'merge --no-ff' to a non-merge commit. Test case by SZEDER Gabor <szeder@xxxxxxxxxx> Signed-off-by: Miklos Vajna <vmiklos@xxxxxxxxxxxxxx> --- On Fri, Sep 26, 2008 at 05:15:17PM +0200, Miklos Vajna <vmiklos@xxxxxxxxxxxxxx> wrote: > I'll send a patch that does this in a bit. Here it is. builtin-commit.c | 16 +++++++++++++++- builtin-merge.c | 9 +++++++++ t/t7600-merge.sh | 9 +++++++++ 3 files changed, 33 insertions(+), 1 deletions(-) diff --git a/builtin-commit.c b/builtin-commit.c index 55e1087..aac5cb4 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -937,6 +937,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) unsigned char commit_sha1[20]; struct ref_lock *ref_lock; struct commit_list *parents = NULL, **pptr = &parents; + struct stat statbuf; + int allow_fast_forward = 1; git_config(git_commit_config, NULL); @@ -988,7 +990,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix) reflog_msg = "commit"; pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next; } - parents = reduce_heads(parents); + strbuf_reset(&sb); + if (!stat(git_path("MERGE_MODE"), &statbuf)) { + if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0) + die("could not read MERGE_MODE: %s", strerror(errno)); + printf("debug, contents of buf: '%s'\n",sb.buf); + if (!strcmp(sb.buf, "deny_fast_forward")) { + printf("debug, deny fast forward\n"); + allow_fast_forward = 0; + } + } + if (allow_fast_forward) + parents = reduce_heads(parents); /* Finally, get the commit message */ strbuf_init(&sb, 0); @@ -1040,6 +1053,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) unlink(git_path("MERGE_HEAD")); unlink(git_path("MERGE_MSG")); + unlink(git_path("MERGE_MODE")); unlink(git_path("SQUASH_MSG")); if (commit_index_files()) diff --git a/builtin-merge.c b/builtin-merge.c index 5c65a58..973b167 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -1210,6 +1210,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, 0666); + if (fd < 0) + die("Could open %s for writing", git_path("MERGE_MODE")); + strbuf_reset(&buf); + if (!allow_fast_forward) + strbuf_addf(&buf, "deny_fast_forward"); + 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) { diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 9516f54..98cfc53 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -511,4 +511,13 @@ test_expect_success 'in-index merge' ' test_debug 'gitk --all' +test_expect_success 'merge --no-ff --no-commit && commit' ' + git reset --hard c0 && + git merge --no-ff --no-commit c1 && + EDITOR=: git commit && + verify_parents $c0 $c1 +' + +test_debug 'gitk --all' + test_done -- 1.6.0.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html