Merge branch 'jc/commit-amend-no-edit'
authorJunio C Hamano <gitster@pobox.com>
Sat, 17 Dec 2011 06:33:56 +0000 (22:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 17 Dec 2011 06:33:56 +0000 (22:33 -0800)
* jc/commit-amend-no-edit:
test: commit --amend should honor --no-edit
commit: honour --no-edit
t7501 (commit): modernize style
test: remove a porcelain test that hard-codes commit names
test: add missing "&&" after echo command

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index e36e9adf87d76002784eb26107c25e5d91683229,48bea8f6e2ec1ef9c2957a9a8dc41a0b3c030052..f73ef9c86d22d7189b7e2f4b3241df974a98a802
@@@ -81,7 -81,8 +81,8 @@@ static const char *template_file
  static const char *author_message, *author_message_buffer;
  static char *edit_message, *use_message;
  static char *fixup_message, *squash_message;
- static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff;
+ static int all, also, interactive, patch_interactive, only, amend, signoff;
+ static int edit_flag = -1; /* unspecified */
  static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
  static int no_post_rewrite, allow_empty_message;
  static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
@@@ -141,7 -142,7 +142,7 @@@ static struct option builtin_commit_opt
        OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C-c/--amend)"),
        OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
        OPT_FILENAME('t', "template", &template_file, "use specified template file"),
-       OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
+       OPT_BOOL('e', "edit", &edit_flag, "force edit of commit"),
        OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
        OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
        /* end commit message options */
@@@ -1020,8 -1021,8 +1021,8 @@@ static int parse_and_validate_options(i
  
        if (logfile || message.len || use_message || fixup_message)
                use_editor = 0;
-       if (edit_flag)
-               use_editor = 1;
+       if (0 <= edit_flag)
+               use_editor = edit_flag;
        if (!use_editor)
                setenv("GIT_EDITOR", ":", 1);
  
@@@ -1259,7 -1260,7 +1260,7 @@@ static void print_summary(const char *p
        struct commit *commit;
        struct strbuf format = STRBUF_INIT;
        unsigned char junk_sha1[20];
 -      const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
 +      const char *head;
        struct pretty_print_context pctx = {0};
        struct strbuf author_ident = STRBUF_INIT;
        struct strbuf committer_ident = STRBUF_INIT;
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);
  
 +      head = resolve_ref("HEAD", junk_sha1, 0, NULL);
        printf("[%s%s ",
                !prefixcmp(head, "refs/heads/") ?
                        head + 11 :
@@@ -1383,7 -1383,6 +1384,7 @@@ int cmd_commit(int argc, const char **a
        int allow_fast_forward = 1;
        struct wt_status s;
        struct commit *current_head = NULL;
 +      struct commit_extra_header *extra = NULL;
  
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_commit_usage, builtin_commit_options);
                        pptr = &commit_list_insert(c->item, pptr)->next;
        } else if (whence == FROM_MERGE) {
                struct strbuf m = STRBUF_INIT;
 -              struct commit *commit;
                FILE *fp;
  
                if (!reflog_msg)
                        die_errno(_("could not open '%s' for reading"),
                                  git_path("MERGE_HEAD"));
                while (strbuf_getline(&m, fp, '\n') != EOF) {
 -                      unsigned char sha1[20];
 -                      if (get_sha1_hex(m.buf, sha1) < 0)
 +                      struct commit *parent;
 +
 +                      parent = get_merge_parent(m.buf);
 +                      if (!parent)
                                die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
 -                      commit = lookup_commit_or_die(sha1, "MERGE_HEAD");
 -                      pptr = &commit_list_insert(commit, pptr)->next;
 +                      pptr = &commit_list_insert(parent, pptr)->next;
                }
                fclose(fp);
                strbuf_release(&m);
                exit(1);
        }
  
 -      if (commit_tree(sb.buf, active_cache_tree->sha1, parents, sha1,
 -                      author_ident.buf)) {
 +      if (amend)
 +              extra = read_commit_extra_headers(current_head);
 +
 +      if (commit_tree_extended(sb.buf, active_cache_tree->sha1, parents, sha1,
 +                               author_ident.buf, extra)) {
                rollback_index_files();
                die(_("failed to write commit object"));
        }
        strbuf_release(&author_ident);
 +      free_commit_extra_headers(extra);
  
        ref_lock = lock_any_ref_for_update("HEAD",
                                           !current_head