Merge branch 'jc/rev-parse-argh-dashed-multi-words'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 18:59:27 +0000 (11:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 18:59:27 +0000 (11:59 -0700)
Make sure that the help text given to describe the "<param>" part
of the "git cmd --option=<param>" does not contain SP or _,
e.g. "--gpg-sign=<key-id>" option for "git commit" is not spelled
as "--gpg-sign=<key id>".

* jc/rev-parse-argh-dashed-multi-words:
parse-options: make sure argh string does not have SP or _
update-index: teach --cacheinfo a new syntax "mode,sha1,path"
parse-options: multi-word argh should use dash to separate words

1  2 
Documentation/git-commit.txt
builtin/checkout.c
builtin/commit.c
builtin/merge.c
index 429267abf640ef42b5bf9361ed8ab78f6509f77f,d58758fe1f87f3261d4ca3898d44e1dd4562f5e0..0bbc8f55f9bb558033abb877bf0bc6cd10335edd
@@@ -13,7 -13,7 +13,7 @@@ SYNOPSI
           [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
           [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
           [--date=<date>] [--cleanup=<mode>] [--[no-]status]
-          [-i | -o] [-S[<keyid>]] [--] [<file>...]
+          [-i | -o] [-S[<key-id>]] [--] [<file>...]
  
  DESCRIPTION
  -----------
@@@ -176,7 -176,7 +176,7 @@@ OPTION
  --cleanup=<mode>::
        This option determines how the supplied commit message should be
        cleaned up before committing.  The '<mode>' can be `strip`,
 -      `whitespace`, `verbatim`, or `default`.
 +      `whitespace`, `verbatim`, `scissors` or `default`.
  +
  --
  strip::
@@@ -186,12 -186,6 +186,12 @@@ whitespace:
        Same as `strip` except #commentary is not removed.
  verbatim::
        Do not change the message at all.
 +scissors::
 +      Same as `whitespace`, except that everything from (and
 +      including) the line
 +      "`# ------------------------ >8 ------------------------`"
 +      is truncated if the message is to be edited. "`#`" can be
 +      customized with core.commentChar.
  default::
        Same as `strip` if the message is to be edited.
        Otherwise `whitespace`.
diff --combined builtin/checkout.c
index 1b86d9c868c35c7f0ad3f4b39f9d225c8365c77c,a0e72d21e0489c5bed53a4feedc05c4defb6e470..5b07757d4fca1950e293edf4a1183e5f79a72a2f
@@@ -53,10 -53,10 +53,10 @@@ struct checkout_opts 
  static int post_checkout_hook(struct commit *old, struct commit *new,
                              int changed)
  {
 -      return run_hook(NULL, "post-checkout",
 -                      sha1_to_hex(old ? old->object.sha1 : null_sha1),
 -                      sha1_to_hex(new ? new->object.sha1 : null_sha1),
 -                      changed ? "1" : "0", NULL);
 +      return run_hook_le(NULL, "post-checkout",
 +                         sha1_to_hex(old ? old->object.sha1 : null_sha1),
 +                         sha1_to_hex(new ? new->object.sha1 : null_sha1),
 +                         changed ? "1" : "0", NULL);
        /* "new" can be NULL when checking out from the index before
           a commit exists. */
  
@@@ -1095,7 -1095,7 +1095,7 @@@ int cmd_checkout(int argc, const char *
                OPT_BOOL(0, "detach", &opts.force_detach, N_("detach the HEAD at named commit")),
                OPT_SET_INT('t', "track",  &opts.track, N_("set upstream info for new branch"),
                        BRANCH_TRACK_EXPLICIT),
-               OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new branch"), N_("new unparented branch")),
+               OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")),
                OPT_SET_INT('2', "ours", &opts.writeout_stage, N_("checkout our version for unmerged files"),
                            2),
                OPT_SET_INT('3', "theirs", &opts.writeout_stage, N_("checkout their version for unmerged files"),
diff --combined builtin/commit.c
index d9550c54d02bbd1ba4df87734433dea4a7097e2e,96bf7620c52a2c853d5d7701395168aeb6be8d94..215b5bec192777b36953c76fa8b15c5b14a8a643
@@@ -113,7 -113,6 +113,7 @@@ static char *sign_commit
  static enum {
        CLEANUP_SPACE,
        CLEANUP_NONE,
 +      CLEANUP_SCISSORS,
        CLEANUP_ALL
  } cleanup_mode;
  static const char *cleanup_arg;
@@@ -611,7 -610,7 +611,7 @@@ static int prepare_to_commit(const cha
        /* This checks and barfs if author is badly specified */
        determine_author_info(author_ident);
  
 -      if (!no_verify && run_hook(index_file, "pre-commit", NULL))
 +      if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
                return 0;
  
        if (squash_message) {
                int ident_shown = 0;
                int saved_color_setting;
                char *ai_tmp, *ci_tmp;
 -              if (whence != FROM_COMMIT)
 +              if (whence != FROM_COMMIT) {
 +                      if (cleanup_mode == CLEANUP_SCISSORS)
 +                              wt_status_add_cut_line(s->fp);
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                            whence == FROM_MERGE
                                ? _("\n"
                                git_path(whence == FROM_MERGE
                                         ? "MERGE_HEAD"
                                         : "CHERRY_PICK_HEAD"));
 +              }
  
                fprintf(s->fp, "\n");
                if (cleanup_mode == CLEANUP_ALL)
                                _("Please enter the commit message for your changes."
                                  " Lines starting\nwith '%c' will be ignored, and an empty"
                                  " message aborts the commit.\n"), comment_line_char);
 +              else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
 +                      wt_status_add_cut_line(s->fp);
                else /* CLEANUP_SPACE, that is. */
                        status_printf(s, GIT_COLOR_NORMAL,
                                _("Please enter the commit message for your changes."
                return 0;
        }
  
 -      if (run_hook(index_file, "prepare-commit-msg",
 -                   git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
 +      if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
 +                          git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
                return 0;
  
        if (use_editor) {
        }
  
        if (!no_verify &&
 -          run_hook(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;
        }
  
@@@ -1074,6 -1068,8 +1074,6 @@@ static int parse_and_validate_options(i
                use_editor = 0;
        if (0 <= edit_flag)
                use_editor = edit_flag;
 -      if (!use_editor)
 -              setenv("GIT_EDITOR", ":", 1);
  
        /* Sanity check options */
        if (amend && !current_head)
                cleanup_mode = CLEANUP_SPACE;
        else if (!strcmp(cleanup_arg, "strip"))
                cleanup_mode = CLEANUP_ALL;
 +      else if (!strcmp(cleanup_arg, "scissors"))
 +              cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
        else
                die(_("Invalid cleanup mode %s"), cleanup_arg);
  
@@@ -1456,29 -1450,6 +1456,29 @@@ static int run_rewrite_hook(const unsig
        return finish_command(&proc);
  }
  
 +int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
 +{
 +      const char *hook_env[3] =  { NULL };
 +      char index[PATH_MAX];
 +      va_list args;
 +      int ret;
 +
 +      snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
 +      hook_env[0] = index;
 +
 +      /*
 +       * Let the hook know that no editor will be launched.
 +       */
 +      if (!editor_is_used)
 +              hook_env[1] = "GIT_EDITOR=:";
 +
 +      va_start(args, name);
 +      ret = run_hook_ve(hook_env, name, args);
 +      va_end(args);
 +
 +      return ret;
 +}
 +
  int cmd_commit(int argc, const char **argv, const char *prefix)
  {
        static struct wt_status s;
                OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
                OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")),
                OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")),
-               { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
+               { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
                  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
                /* end commit message options */
  
                die(_("could not read commit message: %s"), strerror(saved_errno));
        }
  
 -      /* Truncate the message just before the diff, if any. */
 -      if (verbose)
 +      if (verbose || /* Truncate the message just before the diff, if any. */
 +          cleanup_mode == CLEANUP_SCISSORS)
                wt_status_truncate_message_at_cut_line(&sb);
  
        if (cleanup_mode != CLEANUP_NONE)
                     "not exceeded, and then \"git reset HEAD\" to recover."));
  
        rerere(0);
 -      run_hook(get_index_file(), "post-commit", NULL);
 +      run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
        if (amend && !no_post_rewrite) {
                struct notes_rewrite_cfg *cfg;
                cfg = init_copy_notes_for_rewrite("amend");
diff --combined builtin/merge.c
index e15d0e145a51d52687619673aec3ee80c0485375,2a144e1200d6ee0ddbe2ff13aea6f99157a4b291..66d8843301b22a6a89d9d765e9d3020942e6f672
@@@ -220,7 -220,7 +220,7 @@@ static struct option builtin_merge_opti
        OPT_BOOL(0, "abort", &abort_current_merge,
                N_("abort the current in-progress merge")),
        OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
-       { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
+       { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
          N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
        OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
        OPT_END()
@@@ -421,7 -421,7 +421,7 @@@ static void finish(struct commit *head_
        }
  
        /* Run a post-merge hook */
 -      run_hook(NULL, "post-merge", squash ? "1" : "0", NULL);
 +      run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL);
  
        strbuf_release(&reflog_message);
  }
@@@ -824,8 -824,8 +824,8 @@@ static void prepare_to_commit(struct co
        if (0 < option_edit)
                strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
        write_merge_msg(&msg);
 -      if (run_hook(get_index_file(), "prepare-commit-msg",
 -                   git_path("MERGE_MSG"), "merge", NULL, NULL))
 +      if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
 +                          git_path("MERGE_MSG"), "merge", NULL))
                abort_commit(remoteheads, NULL);
        if (0 < option_edit) {
                if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))