Merge branch 'pb/commit-verbose-config'
authorJunio C Hamano <gitster@pobox.com>
Mon, 23 May 2016 21:54:31 +0000 (14:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 May 2016 21:54:32 +0000 (14:54 -0700)
"git commit" learned to pay attention to "commit.verbose"
configuration variable and act as if "--verbose" option was
given from the command line.

* pb/commit-verbose-config:
commit: add a commit.verbose config variable
t7507-commit-verbose: improve test coverage by testing number of diffs
parse-options.c: make OPTION_COUNTUP respect "unspecified" values
t/t7507: improve test coverage
t0040-parse-options: improve test coverage
test-parse-options: print quiet as integer
t0040-test-parse-options.sh: fix style issues

1  2 
Documentation/config.txt
builtin/commit.c
t/helper/test-parse-options.c
diff --combined Documentation/config.txt
index ea928a729fc780e58a6621f5982684751e2a2087,8bf60409f7dbd688f8836c460ce7ef624f071ec0..53f00dbc267db194c7c5558a008fd9d8ec20068c
@@@ -81,16 -81,13 +81,16 @@@ Include
  
  You can include one config file from another by setting the special
  `include.path` variable to the name of the file to be included. The
 +variable takes a pathname as its value, and is subject to tilde
 +expansion.
 +
 +The
  included file is expanded immediately, as if its contents had been
  found at the location of the include directive. If the value of the
  `include.path` variable is a relative path, the path is considered to be
  relative to the configuration file in which the include directive was
 -found. The value of `include.path` is subject to tilde expansion: `~/`
 -is expanded to the value of `$HOME`, and `~user/` to the specified
 -user's home directory. See below for examples.
 +found.  See below for examples.
 +
  
  Example
  ~~~~~~~
        [include]
                path = /path/to/foo.inc ; include by absolute path
                path = foo ; expand "foo" relative to the current file
 -              path = ~/foo ; expand "foo" in your $HOME directory
 +              path = ~/foo ; expand "foo" in your `$HOME` directory
  
  
  Values
@@@ -172,13 -169,6 +172,13 @@@ thing on the same output line (e.g. ope
  list of branch names in `log --decorate` output) is set to be
  painted with `bold` or some other attribute.
  
 +pathname::
 +      A variable that takes a pathname value can be given a
 +      string that begins with "`~/`" or "`~user/`", and the usual
 +      tilde expansion happens to such a string: `~/`
 +      is expanded to the value of `$HOME`, and `~user/` to the
 +      specified user's home directory.
 +
  
  Variables
  ~~~~~~~~~
@@@ -279,12 -269,6 +279,12 @@@ See linkgit:git-update-index[1]
  +
  The default is true (when core.filemode is not specified in the config file).
  
 +core.hideDotFiles::
 +      (Windows-only) If true, mark newly-created directories and files whose
 +      name starts with a dot as hidden.  If 'dotGitOnly', only the `.git/`
 +      directory is hidden, but no other files starting with a dot.  The
 +      default mode is 'dotGitOnly'.
 +
  core.ignoreCase::
        If true, this option enables various workarounds to enable
        Git to work better on filesystems that are not case sensitive,
@@@ -353,9 -337,9 +353,9 @@@ core.quotePath:
  
  core.eol::
        Sets the line ending type to use in the working directory for
 -      files that have the `text` property set.  Alternatives are
 -      'lf', 'crlf' and 'native', which uses the platform's native
 -      line ending.  The default value is `native`.  See
 +      files that have the `text` property set when core.autocrlf is false.
 +      Alternatives are 'lf', 'crlf' and 'native', which uses the platform's
 +      native line ending.  The default value is `native`.  See
        linkgit:gitattributes[5] for more information on end-of-line
        conversion.
  
@@@ -502,10 -486,10 +502,10 @@@ repository's usual working tree)
  
  core.logAllRefUpdates::
        Enable the reflog. Updates to a ref <ref> is logged to the file
 -      "$GIT_DIR/logs/<ref>", by appending the new and old
 +      "`$GIT_DIR/logs/<ref>`", by appending the new and old
        SHA-1, the date/time and the reason of the update, but
        only when the file exists.  If this configuration
 -      variable is set to true, missing "$GIT_DIR/logs/<ref>"
 +      variable is set to true, missing "`$GIT_DIR/logs/<ref>`"
        file is automatically created for branch heads (i.e. under
        refs/heads/), remote refs (i.e. under refs/remotes/),
        note refs (i.e. under refs/notes/), and the symbolic ref HEAD.
@@@ -609,11 -593,12 +609,11 @@@ be delta compressed, but larger binary 
  Common unit suffixes of 'k', 'm', or 'g' are supported.
  
  core.excludesFile::
 -      In addition to '.gitignore' (per-directory) and
 -      '.git/info/exclude', Git looks into this file for patterns
 -      of files which are not meant to be tracked.  "`~/`" is expanded
 -      to the value of `$HOME` and "`~user/`" to the specified user's
 -      home directory. Its default value is $XDG_CONFIG_HOME/git/ignore.
 -      If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore
 +      Specifies the pathname to the file that contains patterns to
 +      describe paths that are not meant to be tracked, in addition
 +      to '.gitignore' (per-directory) and '.git/info/exclude'.
 +      Defaults to `$XDG_CONFIG_HOME/git/ignore`.
 +      If `$XDG_CONFIG_HOME` is either not set or empty, `$HOME/.config/git/ignore`
        is used instead. See linkgit:gitignore[5].
  
  core.askPass::
@@@ -630,25 -615,8 +630,25 @@@ core.attributesFile:
        '.git/info/attributes', Git looks into this file for attributes
        (see linkgit:gitattributes[5]). Path expansions are made the same
        way as for `core.excludesFile`. Its default value is
 -      $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not
 -      set or empty, $HOME/.config/git/attributes is used instead.
 +      `$XDG_CONFIG_HOME/git/attributes`. If `$XDG_CONFIG_HOME` is either not
 +      set or empty, `$HOME/.config/git/attributes` is used instead.
 +
 +core.hooksPath::
 +      By default Git will look for your hooks in the
 +      '$GIT_DIR/hooks' directory. Set this to different path,
 +      e.g. '/etc/git/hooks', and Git will try to find your hooks in
 +      that directory, e.g. '/etc/git/hooks/pre-receive' instead of
 +      in '$GIT_DIR/hooks/pre-receive'.
 ++
 +The path can be either absolute or relative. A relative path is
 +taken as relative to the directory where the hooks are run (see
 +the "DESCRIPTION" section of linkgit:githooks[5]).
 ++
 +This configuration variable is useful in cases where you'd like to
 +centrally configure your Git hooks instead of configuring them on a
 +per-repository basis, or as a more flexible and centralized
 +alternative to having an `init.templateDir` where you've changed
 +default hooks.
  
  core.editor::
        Commands such as `commit` and `tag` that lets you edit
@@@ -1138,9 -1106,14 +1138,13 @@@ commit.status:
        message.  Defaults to true.
  
  commit.template::
 -      Specify a file to use as the template for new commit messages.
 -      "`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
 -      specified user's home directory.
 +      Specify the pathname of a file to use as the template for
 +      new commit messages.
  
+ commit.verbose::
+       A boolean or int to specify the level of verbose with `git commit`.
+       See linkgit:git-commit[1].
  credential.helper::
        Specify an external helper to be called when a username or
        password credential is needed; the helper may consult external
@@@ -1290,10 -1263,6 +1294,10 @@@ format.outputDirectory:
        Set a custom directory to store the resulting files instead of the
        current working directory.
  
 +format.useAutoBase::
 +      A boolean value which lets you enable the `--base=auto` option of
 +      format-patch by default.
 +
  filter.<driver>.clean::
        The command which is used to convert the content of a worktree
        file to a blob upon checkin.  See linkgit:gitattributes[5] for
@@@ -1370,7 -1339,7 +1374,7 @@@ gc.worktreePruneExpire:
        'git worktree prune --expire 3.months.ago'.
        This config variable can be used to set a different grace
        period. The value "now" may be used to disable the grace
 -      period and prune $GIT_DIR/worktrees immediately, or "never"
 +      period and prune `$GIT_DIR/worktrees` immediately, or "never"
        may be used to suppress pruning.
  
  gc.reflogExpire::
@@@ -1510,13 -1479,13 +1514,13 @@@ grep.fallbackToNoIndex:
        is executed outside of a git repository.  Defaults to false.
  
  gpg.program::
 -      Use this custom program instead of "gpg" found on $PATH when
 +      Use this custom program instead of "`gpg`" found on `$PATH` when
        making or verifying a PGP signature. The program must support the
        same command-line interface as GPG, namely, to verify a detached
 -      signature, "gpg --verify $file - <$signature" is run, and the
 +      signature, "`gpg --verify $file - <$signature`" is run, and the
        program is expected to signal a good signature by exiting with
        code 0, and to generate an ASCII-armored detached signature, the
 -      standard input of "gpg -bsau $key" is fed with the contents to be
 +      standard input of "`gpg -bsau $key`" is fed with the contents to be
        signed, and the program is expected to send the result to its
        standard output.
  
@@@ -1529,7 -1498,7 +1533,7 @@@ gui.diffContext:
        made by the linkgit:git-gui[1]. The default is "5".
  
  gui.displayUntracked::
 -      Determines if linkgit::git-gui[1] shows untracked files
 +      Determines if linkgit:git-gui[1] shows untracked files
        in the file list. The default is "true".
  
  gui.encoding::
@@@ -1690,19 -1659,12 +1694,19 @@@ http.emptyAuth:
        a username in the URL, as libcurl normally requires a username for
        authentication.
  
 +http.extraHeader::
 +      Pass an additional HTTP header when communicating with a server.  If
 +      more than one such entry exists, all of them are added as extra
 +      headers.  To allow overriding the settings inherited from the system
 +      config, an empty value will reset the extra headers to the empty list.
 +
  http.cookieFile::
 -      File containing previously stored cookie lines which should be used
 +      The pathname of a file containing previously stored cookie lines,
 +      which should be used
        in the Git http session, if they match the server. The file format
        of the file to read cookies from should be plain HTTP headers or
 -      the Netscape/Mozilla cookie file format (see linkgit:curl[1]).
 -      NOTE that the file specified with http.cookieFile is only used as
 +      the Netscape/Mozilla cookie file format (see `curl(1)`).
 +      NOTE that the file specified with http.cookieFile is used only as
        input unless http.saveCookies is set.
  
  http.saveCookies::
@@@ -2198,11 -2160,8 +2202,11 @@@ pack.packSizeLimit:
        The maximum size of a pack.  This setting only affects
        packing to a file when repacking, i.e. the git:// protocol
        is unaffected.  It can be overridden by the `--max-pack-size`
 -      option of linkgit:git-repack[1]. The minimum size allowed is
 -      limited to 1 MiB. The default is unlimited.
 +      option of linkgit:git-repack[1].  Reaching this limit results
 +      in the creation of multiple packfiles; which in turn prevents
 +      bitmaps from being created.
 +      The minimum size allowed is limited to 1 MiB.
 +      The default is unlimited.
        Common unit suffixes of 'k', 'm', or 'g' are
        supported.
  
@@@ -2602,9 -2561,8 +2606,9 @@@ repack.writeBitmaps:
        objects to disk (e.g., when `git repack -a` is run).  This
        index can speed up the "counting objects" phase of subsequent
        packs created for clones and fetches, at the cost of some disk
 -      space and extra time spent on the initial repack.  Defaults to
 -      false.
 +      space and extra time spent on the initial repack.  This has
 +      no effect if multiple packfiles are created.
 +      Defaults to false.
  
  rerere.autoUpdate::
        When set to true, `git-rerere` updates the index with the
diff --combined builtin/commit.c
index 391126e58d12f4683e131a310d94d6de4571c7e6,a4866205534f067932cae7329767d0a8db19f878..443ff9196d16a9b6fc2d1d8b22393b1533faeb8f
@@@ -114,6 -114,7 +114,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;
@@@ -695,7 -696,7 +696,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, "-")) {
@@@ -1172,9 -1173,9 +1173,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;
@@@ -1515,6 -1516,11 +1516,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)
@@@ -1661,9 -1667,13 +1667,13 @@@ int cmd_commit(int argc, const char **a
                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);
index 2c8c8f18edb46378b39c170b4ae6f7250ec631f5,0000000000000000000000000000000000000000..f02c275f3335f392243426594a82b759e6f3eed9
mode 100644,000000..100644
--- /dev/null
@@@ -1,104 -1,0 +1,105 @@@
- static int verbose = 0, dry_run = 0, quiet = 0;
 +#include "cache.h"
 +#include "parse-options.h"
 +#include "string-list.h"
 +
 +static int boolean = 0;
 +static int integer = 0;
 +static unsigned long magnitude = 0;
 +static unsigned long timestamp;
 +static int abbrev = 7;
-       printf("quiet: %s\n", quiet ? "yes" : "no");
++static int verbose = -1; /* unspecified */
++static int dry_run = 0, quiet = 0;
 +static char *string = NULL;
 +static char *file = NULL;
 +static int ambiguous;
 +static struct string_list list;
 +
 +static int length_callback(const struct option *opt, const char *arg, int unset)
 +{
 +      printf("Callback: \"%s\", %d\n",
 +              (arg ? arg : "not set"), unset);
 +      if (unset)
 +              return 1; /* do not support unset */
 +
 +      *(int *)opt->value = strlen(arg);
 +      return 0;
 +}
 +
 +static int number_callback(const struct option *opt, const char *arg, int unset)
 +{
 +      *(int *)opt->value = strtol(arg, NULL, 10);
 +      return 0;
 +}
 +
 +int main(int argc, char **argv)
 +{
 +      const char *prefix = "prefix/";
 +      const char *usage[] = {
 +              "test-parse-options <options>",
 +              NULL
 +      };
 +      struct option options[] = {
 +              OPT_BOOL(0, "yes", &boolean, "get a boolean"),
 +              OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
 +              { OPTION_SET_INT, 'B', "no-fear", &boolean, NULL,
 +                "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
 +              OPT_COUNTUP('b', "boolean", &boolean, "increment by one"),
 +              OPT_BIT('4', "or4", &boolean,
 +                      "bitwise-or boolean with ...0100", 4),
 +              OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4),
 +              OPT_GROUP(""),
 +              OPT_INTEGER('i', "integer", &integer, "get a integer"),
 +              OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
 +              OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
 +              OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
 +              OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
 +              OPT_CALLBACK('L', "length", &integer, "str",
 +                      "get length of <str>", length_callback),
 +              OPT_FILENAME('F', "file", &file, "set file to <file>"),
 +              OPT_GROUP("String options"),
 +              OPT_STRING('s', "string", &string, "string", "get a string"),
 +              OPT_STRING(0, "string2", &string, "str", "get another string"),
 +              OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
 +              OPT_STRING('o', NULL, &string, "str", "get another string"),
 +              OPT_NOOP_NOARG(0, "obsolete"),
 +              OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
 +              OPT_GROUP("Magic arguments"),
 +              OPT_ARGUMENT("quux", "means --quux"),
 +              OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
 +                      number_callback),
 +              { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
 +                PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },
 +              { OPTION_COUNTUP, 0, "ambiguous", &ambiguous, NULL,
 +                "positive ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
 +              { OPTION_COUNTUP, 0, "no-ambiguous", &ambiguous, NULL,
 +                "negative ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
 +              OPT_GROUP("Standard options"),
 +              OPT__ABBREV(&abbrev),
 +              OPT__VERBOSE(&verbose, "be verbose"),
 +              OPT__DRY_RUN(&dry_run, "dry run"),
 +              OPT__QUIET(&quiet, "be quiet"),
 +              OPT_END(),
 +      };
 +      int i;
 +
 +      argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
 +
 +      printf("boolean: %d\n", boolean);
 +      printf("integer: %d\n", integer);
 +      printf("magnitude: %lu\n", magnitude);
 +      printf("timestamp: %lu\n", timestamp);
 +      printf("string: %s\n", string ? string : "(not set)");
 +      printf("abbrev: %d\n", abbrev);
 +      printf("verbose: %d\n", verbose);
++      printf("quiet: %d\n", quiet);
 +      printf("dry run: %s\n", dry_run ? "yes" : "no");
 +      printf("file: %s\n", file ? file : "(not set)");
 +
 +      for (i = 0; i < list.nr; i++)
 +              printf("list: %s\n", list.items[i].string);
 +
 +      for (i = 0; i < argc; i++)
 +              printf("arg %02d: %s\n", i, argv[i]);
 +
 +      return 0;
 +}