Skip to content

Commit aaab842

Browse files
pranitbauva1997gitster
authored andcommitted
commit: add a commit.verbose config variable
Add commit.verbose configuration variable as a convenience for those who always prefer --verbose. Add tests to check the behavior introduced by this commit and also to verify that behavior of status doesn't break because of this commit. Helped-by: Junio C Hamano <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de45dbb commit aaab842

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ commit.template::
11101110
"`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
11111111
specified user's home directory.
11121112

1113+
commit.verbose::
1114+
A boolean or int to specify the level of verbose with `git commit`.
1115+
See linkgit:git-commit[1].
1116+
11131117
credential.helper::
11141118
Specify an external helper to be called when a username or
11151119
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

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);

t/t7507-commit-verbose.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,55 @@ test_expect_success 'status does not verbose without --verbose' '
103103
! grep "^diff --git" actual
104104
'
105105

106+
test_expect_success 'setup -v -v' '
107+
echo dirty >file
108+
'
109+
110+
for i in true 1
111+
do
112+
test_expect_success "commit.verbose=$i and --verbose omitted" "
113+
git -c commit.verbose=$i commit --amend &&
114+
test_line_count = 1 out
115+
"
116+
done
117+
118+
for i in false -2 -1 0
119+
do
120+
test_expect_success "commit.verbose=$i and --verbose omitted" "
121+
git -c commit.verbose=$i commit --amend &&
122+
test_line_count = 0 out
123+
"
124+
done
125+
126+
for i in 2 3
127+
do
128+
test_expect_success "commit.verbose=$i and --verbose omitted" "
129+
git -c commit.verbose=$i commit --amend &&
130+
test_line_count = 2 out
131+
"
132+
done
133+
134+
for i in true false -2 -1 0 1 2 3
135+
do
136+
test_expect_success "commit.verbose=$i and --verbose" "
137+
git -c commit.verbose=$i commit --amend --verbose &&
138+
test_line_count = 1 out
139+
"
140+
141+
test_expect_success "commit.verbose=$i and --no-verbose" "
142+
git -c commit.verbose=$i commit --amend --no-verbose &&
143+
test_line_count = 0 out
144+
"
145+
146+
test_expect_success "commit.verbose=$i and -v -v" "
147+
git -c commit.verbose=$i commit --amend -v -v &&
148+
test_line_count = 2 out
149+
"
150+
done
151+
152+
test_expect_success "status ignores commit.verbose=true" '
153+
git -c commit.verbose=true status >actual &&
154+
! grep "^diff --git actual"
155+
'
156+
106157
test_done

0 commit comments

Comments
 (0)