]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-commit.c
git-commit: Allow to amend a merge commit that does not change the tree
[git.git] / builtin-commit.c
index 6c1ace32a432825e4c630f572f0169b82784ecfb..6c2dc390c451d5942521ddef9f046c5f98097dc3 100644 (file)
@@ -27,6 +27,11 @@ static const char * const builtin_commit_usage[] = {
        NULL
 };
 
+static const char * const builtin_status_usage[] = {
+       "git-status [options] [--] <filepattern>...",
+       NULL
+};
+
 static unsigned char head_sha1[20], merge_head_sha1[20];
 static char *use_message_buffer;
 static const char commit_editmsg[] = "COMMIT_EDITMSG";
@@ -346,11 +351,9 @@ static int prepare_log_message(const char *index_file, const char *prefix)
 
                strbuf_init(&sob, 0);
                strbuf_addstr(&sob, sign_off_header);
-               strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
-                                             getenv("GIT_COMMITTER_EMAIL"),
-                                             "", 1));
+               strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
+                                            getenv("GIT_COMMITTER_EMAIL")));
                strbuf_addch(&sob, '\n');
-
                for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
                        ; /* do nothing */
                if (prefixcmp(sb.buf + i, sob.buf)) {
@@ -495,12 +498,12 @@ static void determine_author_info(struct strbuf *sb)
        strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, 1));
 }
 
-static int parse_and_validate_options(int argc, const char *argv[])
+static int parse_and_validate_options(int argc, const char *argv[],
+                                     const char * const usage[])
 {
        int f = 0;
 
-       argc = parse_options(argc, argv, builtin_commit_options,
-                            builtin_commit_usage, 0);
+       argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
 
        if (logfile || message.len || use_message)
                no_edit = 1;
@@ -597,7 +600,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        git_config(git_status_config);
 
-       argc = parse_and_validate_options(argc, argv);
+       argc = parse_and_validate_options(argc, argv, builtin_status_usage);
 
        index_file = prepare_index(argv, prefix);
 
@@ -673,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"
@@ -689,7 +700,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        git_config(git_commit_config);
 
-       argc = parse_and_validate_options(argc, argv);
+       argc = parse_and_validate_options(argc, argv, builtin_commit_usage);
 
        index_file = prepare_index(argv, prefix);
 
@@ -698,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);