]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-commit.c
commit: allow --amend to reuse message from another commit
[git.git] / builtin-commit.c
index 30a9debcda9fc478571590fe45dc8647cef434fe..518ebe0347e631c72f4e2a83b948259ee20fd213 100644 (file)
@@ -280,7 +280,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
        return false_lock.filename;
 }
 
-static int run_status(FILE *fp, const char *index_file, const char *prefix)
+static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
 {
        struct wt_status s;
 
@@ -296,6 +296,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
        s.untracked = untracked_files;
        s.index_file = index_file;
        s.fp = fp;
+       s.nowarn = nowarn;
 
        wt_status_print(&s);
 
@@ -412,7 +413,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
 
        saved_color_setting = wt_status_use_color;
        wt_status_use_color = 0;
-       commitable = run_status(fp, index_file, prefix);
+       commitable = run_status(fp, index_file, prefix, 1);
        wt_status_use_color = saved_color_setting;
 
        fclose(fp);
@@ -497,7 +498,7 @@ static void determine_author_info(struct strbuf *sb)
                email = xstrndup(lb + 2, rb - (lb + 2));
        }
 
-       strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, 1));
+       strbuf_addf(sb, "author %s\n", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));
 }
 
 static int parse_and_validate_options(int argc, const char *argv[],
@@ -536,7 +537,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
                die("Option -m cannot be combined with -c/-C/-F.");
        if (edit_message)
                use_message = edit_message;
-       if (amend)
+       if (amend && !use_message)
                use_message = "HEAD";
        if (use_message) {
                unsigned char sha1[20];
@@ -606,7 +607,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        index_file = prepare_index(argc, argv, prefix);
 
-       commitable = run_status(stdout, index_file, prefix);
+       commitable = run_status(stdout, index_file, prefix, 0);
 
        rollback_index_files();
 
@@ -660,12 +661,16 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
        rev.verbose_header = 1;
        rev.show_root_diff = 1;
        rev.commit_format = get_commit_format("format:%h: %s");
-       rev.always_show_header = 1;
+       rev.always_show_header = 0;
 
        printf("Created %scommit ", initial_commit ? "initial " : "");
 
-       log_tree_commit(&rev, commit);
-       printf("\n");
+       if (!log_tree_commit(&rev, commit)) {
+               struct strbuf buf = STRBUF_INIT;
+               format_commit_message(commit, "%h: %s", &buf);
+               printf("%s\n", buf.buf);
+               strbuf_release(&buf);
+       }
 }
 
 int git_commit_config(const char *k, const char *v)
@@ -713,7 +718,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        if (!prepare_log_message(index_file, prefix) && !in_merge &&
            !allow_empty && !(amend && is_a_merge(head_sha1))) {
-               run_status(stdout, index_file, prefix);
+               run_status(stdout, index_file, prefix, 0);
                rollback_index_files();
                unlink(commit_editmsg);
                return 1;
@@ -776,7 +781,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        }
 
        determine_author_info(&sb);
-       strbuf_addf(&sb, "committer %s\n", git_committer_info(1));
+       strbuf_addf(&sb, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
        if (!is_encoding_utf8(git_commit_encoding))
                strbuf_addf(&sb, "encoding %s\n", git_commit_encoding);
        strbuf_addch(&sb, '\n');