Skip to content

Commit 5d5f1c2

Browse files
committed
Merge branch 'pb/commit-verbose-config'
"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
2 parents 72ce3ff + aaab842 commit 5d5f1c2

File tree

8 files changed

+268
-74
lines changed

8 files changed

+268
-74
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@ commit.template::
11411141
Specify the pathname of a file to use as the template for
11421142
new commit messages.
11431143

1144+
commit.verbose::
1145+
A boolean or int to specify the level of verbose with `git commit`.
1146+
See linkgit:git-commit[1].
1147+
11441148
credential.helper::
11451149
Specify an external helper to be called when a username or
11461150
password credential is needed; the helper may consult external

Documentation/git-commit.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ configuration variable documented in linkgit:git-config[1].
290290
what changes the commit has.
291291
Note that this diff output doesn't have its
292292
lines prefixed with '#'. This diff will not be a part
293-
of the commit message.
293+
of the commit message. See the `commit.verbose` configuration
294+
variable in linkgit:git-config[1].
294295
+
295296
If specified twice, show in addition the unified diff between
296297
what would be committed and the worktree files, i.e. the unstaged

Documentation/technical/api-parse-options.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ There are some macros to easily define options:
144144

145145
`OPT_COUNTUP(short, long, &int_var, description)`::
146146
Introduce a count-up option.
147-
`int_var` is incremented on each use of `--option`, and
148-
reset to zero with `--no-option`.
147+
Each use of `--option` increments `int_var`, starting from zero
148+
(even if initially negative), and `--no-option` resets it to
149+
zero. To determine if `--option` or `--no-option` was encountered at
150+
all, initialize `int_var` to a negative value, and if it is still
151+
negative after parse_options(), then neither `--option` nor
152+
`--no-option` was seen.
149153

150154
`OPT_BIT(short, long, &int_var, description, mask)`::
151155
Introduce a boolean option.

builtin/commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static char *fixup_message, *squash_message;
114114
static int all, also, interactive, patch_interactive, only, amend, signoff;
115115
static int edit_flag = -1; /* unspecified */
116116
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
117+
static int config_commit_verbose = -1; /* unspecified */
117118
static int no_post_rewrite, allow_empty_message;
118119
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
119120
static char *sign_commit;
@@ -1515,6 +1516,11 @@ static int git_commit_config(const char *k, const char *v, void *cb)
15151516
sign_commit = git_config_bool(k, v) ? "" : NULL;
15161517
return 0;
15171518
}
1519+
if (!strcmp(k, "commit.verbose")) {
1520+
int is_bool;
1521+
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
1522+
return 0;
1523+
}
15181524

15191525
status = git_gpg_config(k, v, NULL);
15201526
if (status)
@@ -1661,9 +1667,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16611667
if (parse_commit(current_head))
16621668
die(_("could not parse HEAD commit"));
16631669
}
1670+
verbose = -1; /* unspecified */
16641671
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
16651672
builtin_commit_usage,
16661673
prefix, current_head, &s);
1674+
if (verbose == -1)
1675+
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
1676+
16671677
if (dry_run)
16681678
return dry_run_commit(argc, argv, prefix, current_head, &s);
16691679
index_file = prepare_index(argc, argv, prefix, current_head, 0);

parse-options.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ static int get_value(struct parse_opt_ctx_t *p,
110110
return 0;
111111

112112
case OPTION_COUNTUP:
113+
if (*(int *)opt->value < 0)
114+
*(int *)opt->value = 0;
113115
*(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
114116
return 0;
115117

t/helper/test-parse-options.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ static int integer = 0;
77
static unsigned long magnitude = 0;
88
static unsigned long timestamp;
99
static int abbrev = 7;
10-
static int verbose = 0, dry_run = 0, quiet = 0;
10+
static int verbose = -1; /* unspecified */
11+
static int dry_run = 0, quiet = 0;
1112
static char *string = NULL;
1213
static char *file = NULL;
1314
static int ambiguous;
@@ -90,7 +91,7 @@ int main(int argc, char **argv)
9091
printf("string: %s\n", string ? string : "(not set)");
9192
printf("abbrev: %d\n", abbrev);
9293
printf("verbose: %d\n", verbose);
93-
printf("quiet: %s\n", quiet ? "yes" : "no");
94+
printf("quiet: %d\n", quiet);
9495
printf("dry run: %s\n", dry_run ? "yes" : "no");
9596
printf("file: %s\n", file ? file : "(not set)");
9697

0 commit comments

Comments
 (0)