@matheusbsbs / matheus-bagliano / commits / 9663c3bc6a
Fork 0

git-commit: Allow to amend a merge commit that does not change the tree

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>

Junio C Hamano committed Dec 2, 2007 at 23:55 UTC 9663c3bc6a04b9b4f63a54b820d3edb16aa95e6d
1 file changed +10 -1
builtin-commit.c
+10 -1
@@ -676,6 +676,14 @@ int git_commit_config(const char *k, const char *v)
676 return git_status_config(k, v);
677 }
678
679 +static int is_a_merge(const unsigned char *sha1)
680 +{
681 + struct commit *commit = lookup_commit(sha1);
682 + if (!commit || parse_commit(commit))
683 + die("could not parse HEAD commit");
684 + return !!(commit->parents && commit->parents->next);
685 +}
686 +
687 static const char commit_utf8_warn[] =
688 "Warning: commit message does not conform to UTF-8.\n"
689 "You may want to amend it after fixing the message, or set the config\n"
@@ -701,7 +709,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
709 return 1;
710 }
711
704 - if (!prepare_log_message(index_file, prefix) && !in_merge) {
712 + if (!prepare_log_message(index_file, prefix) && !in_merge &&
713 + !(amend && is_a_merge(head_sha1))) {
714 run_status(stdout, index_file, prefix);
715 rollback_index_files();
716 unlink(commit_editmsg);