Commit 4f2d651e authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'mv/merge-noff'

* mv/merge-noff:
  builtin-commit: use reduce_heads() only when appropriate

Conflicts:
	builtin-commit.c
	t/t7600-merge.sh
parents ce6e5ff4 cf10f9fd
......@@ -168,5 +168,6 @@ void remove_branch_state(void)
unlink(git_path("MERGE_HEAD"));
unlink(git_path("MERGE_RR"));
unlink(git_path("MERGE_MSG"));
unlink(git_path("MERGE_MODE"));
unlink(git_path("SQUASH_MSG"));
}
......@@ -943,6 +943,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);
......@@ -989,13 +991,22 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
}
fclose(fp);
strbuf_release(&m);
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));
if (!strcmp(sb.buf, "no-ff"))
allow_fast_forward = 0;
}
if (allow_fast_forward)
parents = reduce_heads(parents);
} else {
reflog_msg = "commit";
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
}
parents = reduce_heads(parents);
/* Finally, get the commit message */
strbuf_reset(&sb);
if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
rollback_index_files();
die("could not read commit message");
......@@ -1044,6 +1055,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())
......
......@@ -179,6 +179,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) {
......
......@@ -544,4 +544,20 @@ test_expect_success 'merge early part of c2' '
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_expect_success 'amending no-ff merge commit' '
EDITOR=: git commit --amend &&
verify_parents $c0 $c1
'
test_debug 'gitk --all'
test_done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment