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 <gitster@pobox.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pranit Bauva committed
May 5, 2016 at 15:20 UTC
aaab84203b9654fb73df41d3cb71a6aad3a091fa
4 files changed
+67
-1
Documentation/config.txt
+4
@@ -1110,6 +1110,10 @@ commit.template::
1110
"`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
1111
specified user's home directory.
1112
1113
+commit.verbose::
1114
+ A boolean or int to specify the level of verbose with `git commit`.
1115
+ See linkgit:git-commit[1].
1116
+
1117
credential.helper::
1118
Specify an external helper to be called when a username or
1119
password credential is needed; the helper may consult external
Documentation/git-commit.txt
+2
-1
@@ -290,7 +290,8 @@ configuration variable documented in linkgit:git-config[1].
290
what changes the commit has.
291
Note that this diff output doesn't have its
292
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].
295
+
296
If specified twice, show in addition the unified diff between
297
what would be committed and the worktree files, i.e. the unstaged
builtin/commit.c
+10
@@ -114,6 +114,7 @@ static char *fixup_message, *squash_message;
114
static int all, also, interactive, patch_interactive, only, amend, signoff;
115
static int edit_flag = -1; /* unspecified */
116
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
117
+static int config_commit_verbose = -1; /* unspecified */
118
static int no_post_rewrite, allow_empty_message;
119
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
120
static char *sign_commit;
@@ -1515,6 +1516,11 @@ static int git_commit_config(const char *k, const char *v, void *cb)
1516
sign_commit = git_config_bool(k, v) ? "" : NULL;
1517
return 0;
1518
}
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
+ }
1524
1525
status = git_gpg_config(k, v, NULL);
1526
if (status)
@@ -1661,9 +1667,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1667
if (parse_commit(current_head))
1668
die(_("could not parse HEAD commit"));
1669
}
1670
+ verbose = -1; /* unspecified */
1671
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
1672
builtin_commit_usage,
1673
prefix, current_head, &s);
1674
+ if (verbose == -1)
1675
+ verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
1676
+
1677
if (dry_run)
1678
return dry_run_commit(argc, argv, prefix, current_head, &s);
1679
index_file = prepare_index(argc, argv, prefix, current_head, 0);
t/t7507-commit-verbose.sh
+51
@@ -103,4 +103,55 @@ test_expect_success 'status does not verbose without --verbose' '
103
! grep "^diff --git" actual
104
'
105
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
+
157
test_done