Skip to content

Commit

Permalink
git-commit: Allow to amend a merge commit that does not change the tree
Browse files Browse the repository at this point in the history
Normally, it should not be allowed to generate an empty commit. A merge
commit generated with git 'merge -s ours' does not change the tree (along
the first parent), but merges are not "empty" even if they do not change
the tree. Hence, we should be careful not to forbid this case.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Dec 3, 2007
1 parent 69e7491 commit 9663c3b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,14 @@ int git_commit_config(const char *k, const char *v)
return git_status_config(k, v);
}

static int is_a_merge(const unsigned char *sha1)
{
struct commit *commit = lookup_commit(sha1);
if (!commit || parse_commit(commit))
die("could not parse HEAD commit");
return !!(commit->parents && commit->parents->next);
}

static const char commit_utf8_warn[] =
"Warning: commit message does not conform to UTF-8.\n"
"You may want to amend it after fixing the message, or set the config\n"
Expand All @@ -701,7 +709,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
return 1;
}

if (!prepare_log_message(index_file, prefix) && !in_merge) {
if (!prepare_log_message(index_file, prefix) && !in_merge &&
!(amend && is_a_merge(head_sha1))) {
run_status(stdout, index_file, prefix);
rollback_index_files();
unlink(commit_editmsg);
Expand Down

0 comments on commit 9663c3b

Please sign in to comment.