mirror of
https://github.com/git/git.git
synced 2024-11-09 02:33:11 +01:00
1a72cfd7fa
When using the '-v' option of "git commit" the diff added to the commit message temporarily for editing is stripped off after the user exited the editor by searching for "\ndiff --git " and truncating the commmit message there if it is found. But this approach has two problems: - when the commit message itself contains a line starting with "diff --git" it will be truncated there prematurely; and - when the "diff.submodule" setting is set to "log", the diff may start with "Submodule <hash1>..<hash2>", which will be left in the commit message while it shouldn't. Fix that by introducing a special scissor separator line starting with the comment character ('#' or the core.commentChar config if set) followed by two lines describing what it is for. The scissor line - which will not be translated - is used to reliably detect the start of the diff so it can be chopped off from the commit message, no matter what the user enters there. Turn a known test failure fixed by this change into a successful test; also add one for a diff starting with a submodule log and another one for proper handling of the comment char. Reported-by: Ari Pollak <ari@debian.org> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
99 lines
2 KiB
Bash
Executable file
99 lines
2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='verbose commit template'
|
|
. ./test-lib.sh
|
|
|
|
cat >check-for-diff <<EOF
|
|
#!$SHELL_PATH
|
|
exec grep '^diff --git' "\$1"
|
|
EOF
|
|
chmod +x check-for-diff
|
|
test_set_editor "$PWD/check-for-diff"
|
|
|
|
cat >message <<'EOF'
|
|
subject
|
|
|
|
body
|
|
EOF
|
|
|
|
test_expect_success 'setup' '
|
|
echo content >file &&
|
|
git add file &&
|
|
git commit -F message
|
|
'
|
|
|
|
test_expect_success 'initial commit shows verbose diff' '
|
|
git commit --amend -v
|
|
'
|
|
|
|
test_expect_success 'second commit' '
|
|
echo content modified >file &&
|
|
git add file &&
|
|
git commit -F message
|
|
'
|
|
|
|
check_message() {
|
|
git log -1 --pretty=format:%s%n%n%b >actual &&
|
|
test_cmp "$1" actual
|
|
}
|
|
|
|
test_expect_success 'verbose diff is stripped out' '
|
|
git commit --amend -v &&
|
|
check_message message
|
|
'
|
|
|
|
test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
|
|
git config diff.mnemonicprefix true &&
|
|
git commit --amend -v &&
|
|
check_message message
|
|
'
|
|
|
|
cat >diff <<'EOF'
|
|
This is an example commit message that contains a diff.
|
|
|
|
diff --git c/file i/file
|
|
new file mode 100644
|
|
index 0000000..f95c11d
|
|
--- /dev/null
|
|
+++ i/file
|
|
@@ -0,0 +1 @@
|
|
+this is some content
|
|
EOF
|
|
|
|
test_expect_success 'diff in message is retained without -v' '
|
|
git commit --amend -F diff &&
|
|
check_message diff
|
|
'
|
|
|
|
test_expect_success 'diff in message is retained with -v' '
|
|
git commit --amend -F diff -v &&
|
|
check_message diff
|
|
'
|
|
|
|
test_expect_success 'submodule log is stripped out too with -v' '
|
|
git config diff.submodule log &&
|
|
git submodule add ./. sub &&
|
|
git commit -m "sub added" &&
|
|
(
|
|
cd sub &&
|
|
echo "more" >>file &&
|
|
git commit -a -m "submodule commit"
|
|
) &&
|
|
(
|
|
GIT_EDITOR=cat &&
|
|
export GIT_EDITOR &&
|
|
test_must_fail git commit -a -v 2>err
|
|
) &&
|
|
test_i18ngrep "Aborting commit due to empty commit message." err
|
|
'
|
|
|
|
test_expect_success 'verbose diff is stripped out with set core.commentChar' '
|
|
(
|
|
GIT_EDITOR=cat &&
|
|
export GIT_EDITOR &&
|
|
test_must_fail git -c core.commentchar=";" commit -a -v 2>err
|
|
) &&
|
|
test_i18ngrep "Aborting commit due to empty commit message." err
|
|
'
|
|
|
|
test_done
|