Merge branch 'os/no-verify-skips-commit-msg-too' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:25 +0000 (11:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:25 +0000 (11:55 -0700)
"git commit --help" said "--no-verify" is only about skipping the
pre-commit hook, and failed to say that it also skipped the
commit-msg hook.

* os/no-verify-skips-commit-msg-too:
commit: describe that --no-verify skips the commit-msg hook in the help text

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index 1f6dbcd0d06a54eadc0d99a676adf3a9203aca61,99076fa338aa2b7797ac68df243dff09e8c78c0c..77e3dc849419e697abe8f2f4c7d753cce17634a8
@@@ -32,7 -32,6 +32,7 @@@
  #include "sequencer.h"
  #include "notes-utils.h"
  #include "mailmap.h"
 +#include "sigchain.h"
  
  static const char * const builtin_commit_usage[] = {
        N_("git commit [<options>] [--] <pathspec>..."),
@@@ -92,9 -91,8 +92,9 @@@ N_("If you wish to skip this commit, us
  "Then \"git cherry-pick --continue\" will resume cherry-picking\n"
  "the remaining commits.\n");
  
 +static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 +
  static const char *use_message_buffer;
 -static const char commit_editmsg[] = "COMMIT_EDITMSG";
  static struct lock_file index_lock; /* real index */
  static struct lock_file false_lock; /* used only for partial commits */
  static enum {
@@@ -115,7 -113,6 +115,7 @@@ static char *fixup_message, *squash_mes
  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 config_commit_verbose = -1; /* unspecified */
  static int no_post_rewrite, allow_empty_message;
  static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
  static char *sign_commit;
@@@ -169,11 -166,11 +169,11 @@@ static int opt_parse_m(const struct opt
  
  static void determine_whence(struct wt_status *s)
  {
 -      if (file_exists(git_path("MERGE_HEAD")))
 +      if (file_exists(git_path_merge_head()))
                whence = FROM_MERGE;
 -      else if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
 +      else if (file_exists(git_path_cherry_pick_head())) {
                whence = FROM_CHERRY_PICK;
 -              if (file_exists(git_path("sequencer")))
 +              if (file_exists(git_path(SEQ_DIR)))
                        sequencer_in_use = 1;
        }
        else
@@@ -188,7 -185,6 +188,7 @@@ static void status_init_config(struct w
        gitmodules_config();
        git_config(fn, s);
        determine_whence(s);
 +      init_diff_ui_defaults();
        s->hints = advice_status_hints; /* must come after git_config() */
  }
  
@@@ -303,7 -299,7 +303,7 @@@ static void create_base_index(const str
        opts.dst_index = &the_index;
  
        opts.fn = oneway_merge;
 -      tree = parse_tree_indirect(current_head->object.sha1);
 +      tree = parse_tree_indirect(current_head->object.oid.hash);
        if (!tree)
                die(_("failed to unpack HEAD tree object"));
        parse_tree(tree);
@@@ -328,7 -324,6 +328,7 @@@ static const char *prepare_index(int ar
        struct string_list partial;
        struct pathspec pathspec;
        int refresh_flags = REFRESH_QUIET;
 +      const char *ret;
  
        if (is_status)
                refresh_flags |= REFRESH_UNMERGED;
                        die(_("unable to create temporary index"));
  
                old_index_env = getenv(INDEX_ENVIRONMENT);
 -              setenv(INDEX_ENVIRONMENT, index_lock.filename.buf, 1);
 +              setenv(INDEX_ENVIRONMENT, get_lock_file_path(&index_lock), 1);
  
                if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
                        die(_("interactive add failed"));
                        unsetenv(INDEX_ENVIRONMENT);
  
                discard_cache();
 -              read_cache_from(index_lock.filename.buf);
 +              read_cache_from(get_lock_file_path(&index_lock));
                if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
                        if (reopen_lock_file(&index_lock) < 0)
                                die(_("unable to write index file"));
                        warning(_("Failed to update main cache tree"));
  
                commit_style = COMMIT_NORMAL;
 -              return index_lock.filename.buf;
 +              return get_lock_file_path(&index_lock);
        }
  
        /*
         */
        if (all || (also && pathspec.nr)) {
                hold_locked_index(&index_lock, 1);
 -              add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
 +              add_files_to_cache(also ? prefix : NULL, &pathspec, 0, 0);
                refresh_cache_or_die(refresh_flags);
                update_main_cache_tree(WRITE_TREE_SILENT);
                if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to write new_index file"));
                commit_style = COMMIT_NORMAL;
 -              return index_lock.filename.buf;
 +              return get_lock_file_path(&index_lock);
        }
  
        /*
                hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
                if (active_cache_changed
 -                  || !cache_tree_fully_valid(active_cache_tree)) {
 +                  || !cache_tree_fully_valid(active_cache_tree))
                        update_main_cache_tree(WRITE_TREE_SILENT);
 -                      active_cache_changed = 1;
 -              }
                if (active_cache_changed) {
                        if (write_locked_index(&the_index, &index_lock,
                                               COMMIT_LOCK))
                die(_("unable to write temporary index file"));
  
        discard_cache();
 -      read_cache_from(false_lock.filename.buf);
 -
 -      return false_lock.filename.buf;
 +      ret = get_lock_file_path(&false_lock);
 +      read_cache_from(ret);
 +      return ret;
  }
  
  static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
@@@ -697,7 -694,7 +697,7 @@@ static int prepare_to_commit(const cha
                }
        }
  
 -      if (message.len) {
 +      if (have_option_m) {
                strbuf_addbuf(&sb, &message);
                hook_arg1 = "message";
        } else if (logfile && !strcmp(logfile, "-")) {
                char *buffer;
                buffer = strstr(use_message_buffer, "\n\n");
                if (buffer)
 -                      strbuf_addstr(&sb, buffer + 2);
 +                      strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
                hook_arg1 = "commit";
                hook_arg2 = use_message;
        } else if (fixup_message) {
                format_commit_message(commit, "fixup! %s\n\n",
                                      &sb, &ctx);
                hook_arg1 = "message";
 -      } else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
 -              if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
 +      } else if (!stat(git_path_merge_msg(), &statbuf)) {
 +              /*
 +               * prepend SQUASH_MSG here if it exists and a
 +               * "merge --squash" was originally performed
 +               */
 +              if (!stat(git_path_squash_msg(), &statbuf)) {
 +                      if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
 +                              die_errno(_("could not read SQUASH_MSG"));
 +                      hook_arg1 = "squash";
 +              } else
 +                      hook_arg1 = "merge";
 +              if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
                        die_errno(_("could not read MERGE_MSG"));
 -              hook_arg1 = "merge";
 -      } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
 -              if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
 +      } else if (!stat(git_path_squash_msg(), &statbuf)) {
 +              if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
                        die_errno(_("could not read SQUASH_MSG"));
                hook_arg1 = "squash";
        } else if (template_file) {
                hook_arg2 = "";
        }
  
 -      s->fp = fopen(git_path(commit_editmsg), "w");
 +      s->fp = fopen_for_writing(git_path_commit_editmsg());
        if (s->fp == NULL)
 -              die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 +              die_errno(_("could not open '%s'"), git_path_commit_editmsg());
  
        /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
        old_display_comment_prefix = s->display_comment_prefix;
        s->hints = 0;
  
        if (clean_message_contents)
 -              stripspace(&sb, 0);
 +              strbuf_stripspace(&sb, 0);
  
        if (signoff)
                append_signoff(&sb, ignore_non_trailer(&sb), 0);
                                _("%s"
                                "Date:      %s"),
                                ident_shown++ ? "" : "\n",
 -                              show_ident_date(&ai, DATE_NORMAL));
 +                              show_ident_date(&ai, DATE_MODE(NORMAL)));
  
                if (!committer_ident_sufficiently_given())
                        status_printf_ln(s, GIT_COLOR_NORMAL,
        }
  
        if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
 -                          git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
 +                          git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL))
                return 0;
  
        if (use_editor) {
                const char *env[2] = { NULL };
                env[0] =  index;
                snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
 -              if (launch_editor(git_path(commit_editmsg), NULL, env)) {
 +              if (launch_editor(git_path_commit_editmsg(), NULL, env)) {
                        fprintf(stderr,
                        _("Please supply the message using either -m or -F option.\n"));
                        exit(1);
        }
  
        if (!no_verify &&
 -          run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
 +          run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) {
                return 0;
        }
  
@@@ -1027,7 -1015,7 +1027,7 @@@ static int template_untouched(struct st
        if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
                return 0;
  
 -      stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
 +      strbuf_stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
        if (!skip_prefix(sb->buf, tmpl.buf, &start))
                start = sb->buf;
        strbuf_release(&tmpl);
@@@ -1058,7 -1046,7 +1058,7 @@@ static const char *find_author_by_nickn
        commit = get_revision(&revs);
        if (commit) {
                struct pretty_print_context ctx = {0};
 -              ctx.date_mode = DATE_NORMAL;
 +              ctx.date_mode.type = DATE_NORMAL;
                strbuf_release(&buf);
                format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
                clear_mailmap(&mailmap);
@@@ -1174,9 -1162,9 +1174,9 @@@ static int parse_and_validate_options(i
                f++;
        if (f > 1)
                die(_("Only one of -c/-C/-F/--fixup can be used."));
 -      if (message.len && f > 0)
 +      if (have_option_m && f > 0)
                die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
 -      if (f || message.len)
 +      if (f || have_option_m)
                template_file = NULL;
        if (edit_message)
                use_message = edit_message;
@@@ -1378,14 -1366,13 +1378,14 @@@ int cmd_status(int argc, const char **a
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
  
        fd = hold_locked_index(&index_lock, 0);
 -      if (0 <= fd)
 -              update_index_if_able(&the_index, &index_lock);
  
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.ignore_submodule_arg = ignore_submodule_arg;
        wt_status_collect(&s);
  
 +      if (0 <= fd)
 +              update_index_if_able(&the_index, &index_lock);
 +
        if (s.relative_paths)
                s.prefix = prefix;
  
@@@ -1517,11 -1504,6 +1517,11 @@@ static int git_commit_config(const cha
                sign_commit = git_config_bool(k, v) ? "" : NULL;
                return 0;
        }
 +      if (!strcmp(k, "commit.verbose")) {
 +              int is_bool;
 +              config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
 +              return 0;
 +      }
  
        status = git_gpg_config(k, v, NULL);
        if (status)
@@@ -1555,10 -1537,8 +1555,10 @@@ static int run_rewrite_hook(const unsig
                return code;
        n = snprintf(buf, sizeof(buf), "%s %s\n",
                     sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
 +      sigchain_push(SIGPIPE, SIG_IGN);
        write_in_full(proc.in, buf, n);
        close(proc.in);
 +      sigchain_pop(SIGPIPE);
        return finish_command(&proc);
  }
  
@@@ -1617,7 -1597,7 +1617,7 @@@ int cmd_commit(int argc, const char **a
                OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")),
                OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")),
                OPT_BOOL('o', "only", &only, N_("commit only specified files")),
-               OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit hook")),
+               OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),
                OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")),
                OPT_SET_INT(0, "short", &status_format, N_("show status concisely"),
                            STATUS_FORMAT_SHORT),
                if (parse_commit(current_head))
                        die(_("could not parse HEAD commit"));
        }
 +      verbose = -1; /* unspecified */
        argc = parse_and_validate_options(argc, argv, builtin_commit_options,
                                          builtin_commit_usage,
                                          prefix, current_head, &s);
 +      if (verbose == -1)
 +              verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
 +
        if (dry_run)
                return dry_run_commit(argc, argv, prefix, current_head, &s);
        index_file = prepare_index(argc, argv, prefix, current_head, 0);
                if (!reflog_msg)
                        reflog_msg = "commit (merge)";
                pptr = &commit_list_insert(current_head, pptr)->next;
 -              fp = fopen(git_path("MERGE_HEAD"), "r");
 +              fp = fopen(git_path_merge_head(), "r");
                if (fp == NULL)
                        die_errno(_("could not open '%s' for reading"),
 -                                git_path("MERGE_HEAD"));
 -              while (strbuf_getline(&m, fp, '\n') != EOF) {
 +                                git_path_merge_head());
 +              while (strbuf_getline_lf(&m, fp) != EOF) {
                        struct commit *parent;
  
                        parent = get_merge_parent(m.buf);
                }
                fclose(fp);
                strbuf_release(&m);
 -              if (!stat(git_path("MERGE_MODE"), &statbuf)) {
 -                      if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
 +              if (!stat(git_path_merge_mode(), &statbuf)) {
 +                      if (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)
                                die_errno(_("could not read MERGE_MODE"));
                        if (!strcmp(sb.buf, "no-ff"))
                                allow_fast_forward = 0;
  
        /* Finally, get the commit message */
        strbuf_reset(&sb);
 -      if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
 +      if (strbuf_read_file(&sb, git_path_commit_editmsg(), 0) < 0) {
                int saved_errno = errno;
                rollback_index_files();
                die(_("could not read commit message: %s"), strerror(saved_errno));
                wt_status_truncate_message_at_cut_line(&sb);
  
        if (cleanup_mode != CLEANUP_NONE)
 -              stripspace(&sb, cleanup_mode == CLEANUP_ALL);
 +              strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
        if (template_untouched(&sb) && !allow_empty_message) {
                rollback_index_files();
                fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD", sha1,
                                   current_head
 -                                 ? current_head->object.sha1 : null_sha1,
 +                                 ? current_head->object.oid.hash : null_sha1,
                                   0, sb.buf, &err) ||
            ref_transaction_commit(transaction, &err)) {
                rollback_index_files();
        }
        ref_transaction_free(transaction);
  
 -      unlink(git_path("CHERRY_PICK_HEAD"));
 -      unlink(git_path("REVERT_HEAD"));
 -      unlink(git_path("MERGE_HEAD"));
 -      unlink(git_path("MERGE_MSG"));
 -      unlink(git_path("MERGE_MODE"));
 -      unlink(git_path("SQUASH_MSG"));
 +      unlink(git_path_cherry_pick_head());
 +      unlink(git_path_revert_head());
 +      unlink(git_path_merge_head());
 +      unlink(git_path_merge_msg());
 +      unlink(git_path_merge_mode());
 +      unlink(git_path_squash_msg());
  
        if (commit_index_files())
                die (_("Repository has been updated, but unable to write\n"
                cfg = init_copy_notes_for_rewrite("amend");
                if (cfg) {
                        /* we are amending, so current_head is not NULL */
 -                      copy_note_for_rewrite(cfg, current_head->object.sha1, sha1);
 +                      copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1);
                        finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
                }
 -              run_rewrite_hook(current_head->object.sha1, sha1);
 +              run_rewrite_hook(current_head->object.oid.hash, sha1);
        }
        if (!quiet)
                print_summary(prefix, sha1, !current_head);