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
This commit is contained in:
commit
f8eb50f60b
@ -716,6 +716,11 @@ color.ui::
|
|||||||
terminal. When more specific variables of color.* are set, they always
|
terminal. When more specific variables of color.* are set, they always
|
||||||
take precedence over this setting. Defaults to false.
|
take precedence over this setting. Defaults to false.
|
||||||
|
|
||||||
|
commit.status
|
||||||
|
A boolean to enable/disable inclusion of status information in the
|
||||||
|
commit message template when using an editor to prepare the commit
|
||||||
|
message. Defaults to true.
|
||||||
|
|
||||||
commit.template::
|
commit.template::
|
||||||
Specify a file to use as the template for new commit messages.
|
Specify a file to use as the template for new commit messages.
|
||||||
"{tilde}/" is expanded to the value of `$HOME` and "{tilde}user/" to the
|
"{tilde}/" is expanded to the value of `$HOME` and "{tilde}user/" to the
|
||||||
|
@ -11,7 +11,8 @@ SYNOPSIS
|
|||||||
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
|
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
|
||||||
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
|
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
|
||||||
[--allow-empty] [--no-verify] [-e] [--author=<author>]
|
[--allow-empty] [--no-verify] [-e] [--author=<author>]
|
||||||
[--date=<date>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
|
[--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
|
||||||
|
[[-i | -o ]<file>...]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@ -224,6 +225,17 @@ specified.
|
|||||||
to be committed, paths with local changes that will be left
|
to be committed, paths with local changes that will be left
|
||||||
uncommitted and paths that are untracked.
|
uncommitted and paths that are untracked.
|
||||||
|
|
||||||
|
--status::
|
||||||
|
Include the output of linkgit:git-status[1] in the commit
|
||||||
|
message template when using an editor to prepare the commit
|
||||||
|
message. Defaults to on, but can be used to override
|
||||||
|
configuration variable commit.status.
|
||||||
|
|
||||||
|
--no-status::
|
||||||
|
Do not include the output of linkgit:git-status[1] in the
|
||||||
|
commit message template when using an editor to prepare the
|
||||||
|
default commit message.
|
||||||
|
|
||||||
\--::
|
\--::
|
||||||
Do not interpret any more arguments as options.
|
Do not interpret any more arguments as options.
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ static enum {
|
|||||||
} cleanup_mode;
|
} cleanup_mode;
|
||||||
static char *cleanup_arg;
|
static char *cleanup_arg;
|
||||||
|
|
||||||
static int use_editor = 1, initial_commit, in_merge;
|
static int use_editor = 1, initial_commit, in_merge, include_status = 1;
|
||||||
static const char *only_include_assumed;
|
static const char *only_include_assumed;
|
||||||
static struct strbuf message;
|
static struct strbuf message;
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ static struct option builtin_commit_options[] = {
|
|||||||
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
|
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
|
||||||
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
|
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
|
||||||
OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
|
OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
|
||||||
|
OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
|
||||||
/* end commit message options */
|
/* end commit message options */
|
||||||
|
|
||||||
OPT_GROUP("Commit contents options"),
|
OPT_GROUP("Commit contents options"),
|
||||||
@ -590,7 +591,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||||||
|
|
||||||
/* This checks if committer ident is explicitly given */
|
/* This checks if committer ident is explicitly given */
|
||||||
git_committer_info(0);
|
git_committer_info(0);
|
||||||
if (use_editor) {
|
if (use_editor && include_status) {
|
||||||
char *author_ident;
|
char *author_ident;
|
||||||
const char *committer_ident;
|
const char *committer_ident;
|
||||||
|
|
||||||
@ -1105,6 +1106,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
|
|||||||
|
|
||||||
if (!strcmp(k, "commit.template"))
|
if (!strcmp(k, "commit.template"))
|
||||||
return git_config_pathname(&template_file, k, v);
|
return git_config_pathname(&template_file, k, v);
|
||||||
|
if (!strcmp(k, "commit.status")) {
|
||||||
|
include_status = git_config_bool(k, v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return git_status_config(k, v, s);
|
return git_status_config(k, v, s);
|
||||||
}
|
}
|
||||||
|
@ -267,4 +267,113 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat >.git/FAKE_EDITOR <<EOF
|
||||||
|
#!$SHELL_PATH
|
||||||
|
mv "\$1" "\$1.orig"
|
||||||
|
(
|
||||||
|
echo message
|
||||||
|
cat "\$1.orig"
|
||||||
|
) >"\$1"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo '## Custom template' >template
|
||||||
|
|
||||||
|
clear_config () {
|
||||||
|
(
|
||||||
|
git config --unset-all "$1"
|
||||||
|
case $? in
|
||||||
|
0|5) exit 0 ;;
|
||||||
|
*) exit 1 ;;
|
||||||
|
esac
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
try_commit () {
|
||||||
|
git reset --hard &&
|
||||||
|
echo >>negative &&
|
||||||
|
GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
|
||||||
|
case "$use_template" in
|
||||||
|
'')
|
||||||
|
! grep "^## Custom template" .git/COMMIT_EDITMSG ;;
|
||||||
|
*)
|
||||||
|
grep "^## Custom template" .git/COMMIT_EDITMSG ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
try_commit_status_combo () {
|
||||||
|
|
||||||
|
test_expect_success 'commit' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
try_commit "" &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
try_commit "" &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --status' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
try_commit --status &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --no-status' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
try_commit --no-status
|
||||||
|
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit with commit.status = yes' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status yes &&
|
||||||
|
try_commit "" &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit with commit.status = no' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status no &&
|
||||||
|
try_commit "" &&
|
||||||
|
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --status with commit.status = yes' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status yes &&
|
||||||
|
try_commit --status &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --no-status with commit.status = yes' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status yes &&
|
||||||
|
try_commit --no-status &&
|
||||||
|
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --status with commit.status = no' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status no &&
|
||||||
|
try_commit --status &&
|
||||||
|
grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit --no-status with commit.status = no' '
|
||||||
|
clear_config commit.status &&
|
||||||
|
git config commit.status no &&
|
||||||
|
try_commit --no-status &&
|
||||||
|
! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
|
||||||
|
'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try_commit_status_combo
|
||||||
|
|
||||||
|
use_template="-t template"
|
||||||
|
|
||||||
|
try_commit_status_combo
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user