Skip to content

Commit f8eb50f

Browse files
committed
Merge branch 'jh/commit-status'
* jh/commit-status: t7502: test commit.status, --status and --no-status commit: support commit.status, --status, and --no-status Conflicts: Documentation/git-commit.txt builtin-commit.c
2 parents a4c3616 + f9c0181 commit f8eb50f

File tree

4 files changed

+134
-3
lines changed

4 files changed

+134
-3
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@ color.ui::
716716
terminal. When more specific variables of color.* are set, they always
717717
take precedence over this setting. Defaults to false.
718718

719+
commit.status
720+
A boolean to enable/disable inclusion of status information in the
721+
commit message template when using an editor to prepare the commit
722+
message. Defaults to true.
723+
719724
commit.template::
720725
Specify a file to use as the template for new commit messages.
721726
"{tilde}/" is expanded to the value of `$HOME` and "{tilde}user/" to the

Documentation/git-commit.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SYNOPSIS
1111
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
1212
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
1313
[--allow-empty] [--no-verify] [-e] [--author=<author>]
14-
[--date=<date>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
14+
[--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
15+
[[-i | -o ]<file>...]
1516

1617
DESCRIPTION
1718
-----------
@@ -224,6 +225,17 @@ specified.
224225
to be committed, paths with local changes that will be left
225226
uncommitted and paths that are untracked.
226227

228+
--status::
229+
Include the output of linkgit:git-status[1] in the commit
230+
message template when using an editor to prepare the commit
231+
message. Defaults to on, but can be used to override
232+
configuration variable commit.status.
233+
234+
--no-status::
235+
Do not include the output of linkgit:git-status[1] in the
236+
commit message template when using an editor to prepare the
237+
default commit message.
238+
227239
\--::
228240
Do not interpret any more arguments as options.
229241

builtin-commit.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static enum {
6868
} cleanup_mode;
6969
static char *cleanup_arg;
7070

71-
static int use_editor = 1, initial_commit, in_merge;
71+
static int use_editor = 1, initial_commit, in_merge, include_status = 1;
7272
static const char *only_include_assumed;
7373
static struct strbuf message;
7474

@@ -107,6 +107,7 @@ static struct option builtin_commit_options[] = {
107107
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
108108
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
109109
OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
110+
OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
110111
/* end commit message options */
111112

112113
OPT_GROUP("Commit contents options"),
@@ -590,7 +591,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
590591

591592
/* This checks if committer ident is explicitly given */
592593
git_committer_info(0);
593-
if (use_editor) {
594+
if (use_editor && include_status) {
594595
char *author_ident;
595596
const char *committer_ident;
596597

@@ -1105,6 +1106,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
11051106

11061107
if (!strcmp(k, "commit.template"))
11071108
return git_config_pathname(&template_file, k, v);
1109+
if (!strcmp(k, "commit.status")) {
1110+
include_status = git_config_bool(k, v);
1111+
return 0;
1112+
}
11081113

11091114
return git_status_config(k, v, s);
11101115
}

t/t7502-commit.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,113 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
267267
268268
'
269269

270+
cat >.git/FAKE_EDITOR <<EOF
271+
#!$SHELL_PATH
272+
mv "\$1" "\$1.orig"
273+
(
274+
echo message
275+
cat "\$1.orig"
276+
) >"\$1"
277+
EOF
278+
279+
echo '## Custom template' >template
280+
281+
clear_config () {
282+
(
283+
git config --unset-all "$1"
284+
case $? in
285+
0|5) exit 0 ;;
286+
*) exit 1 ;;
287+
esac
288+
)
289+
}
290+
291+
try_commit () {
292+
git reset --hard &&
293+
echo >>negative &&
294+
GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
295+
case "$use_template" in
296+
'')
297+
! grep "^## Custom template" .git/COMMIT_EDITMSG ;;
298+
*)
299+
grep "^## Custom template" .git/COMMIT_EDITMSG ;;
300+
esac
301+
}
302+
303+
try_commit_status_combo () {
304+
305+
test_expect_success 'commit' '
306+
clear_config commit.status &&
307+
try_commit "" &&
308+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
309+
'
310+
311+
test_expect_success 'commit' '
312+
clear_config commit.status &&
313+
try_commit "" &&
314+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
315+
'
316+
317+
test_expect_success 'commit --status' '
318+
clear_config commit.status &&
319+
try_commit --status &&
320+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
321+
'
322+
323+
test_expect_success 'commit --no-status' '
324+
clear_config commit.status &&
325+
try_commit --no-status
326+
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
327+
'
328+
329+
test_expect_success 'commit with commit.status = yes' '
330+
clear_config commit.status &&
331+
git config commit.status yes &&
332+
try_commit "" &&
333+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
334+
'
335+
336+
test_expect_success 'commit with commit.status = no' '
337+
clear_config commit.status &&
338+
git config commit.status no &&
339+
try_commit "" &&
340+
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
341+
'
342+
343+
test_expect_success 'commit --status with commit.status = yes' '
344+
clear_config commit.status &&
345+
git config commit.status yes &&
346+
try_commit --status &&
347+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
348+
'
349+
350+
test_expect_success 'commit --no-status with commit.status = yes' '
351+
clear_config commit.status &&
352+
git config commit.status yes &&
353+
try_commit --no-status &&
354+
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
355+
'
356+
357+
test_expect_success 'commit --status with commit.status = no' '
358+
clear_config commit.status &&
359+
git config commit.status no &&
360+
try_commit --status &&
361+
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
362+
'
363+
364+
test_expect_success 'commit --no-status with commit.status = no' '
365+
clear_config commit.status &&
366+
git config commit.status no &&
367+
try_commit --no-status &&
368+
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
369+
'
370+
371+
}
372+
373+
try_commit_status_combo
374+
375+
use_template="-t template"
376+
377+
try_commit_status_combo
378+
270379
test_done

0 commit comments

Comments
 (0)