mirror of
https://github.com/git/git
synced 2024-09-12 21:04:12 +00:00
de45dbb818
Make the fake "editor" store output of grep in a file so that we can see how many diffs were contained in the message and use them in individual tests where ever it is required. A subsequent commit will introduce scenarios where it is important to be able to exactly determine how many diffs were present. The fake "editor" is always made to succeed regardless of whether grep found diff headers or not so that we don't have to use 'test_must_fail' for which 'test_line_count = 0' is an easy substitute and also helps in maintaining the consistency. Also use write_script() to create the fake "editor". 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>
107 lines
2.2 KiB
Bash
Executable file
107 lines
2.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='verbose commit template'
|
|
. ./test-lib.sh
|
|
|
|
write_script "check-for-diff" <<\EOF &&
|
|
grep '^diff --git' "$1" >out
|
|
exit 0
|
|
EOF
|
|
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_line_count = 1 out
|
|
'
|
|
|
|
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_line_count = 1 out
|
|
'
|
|
|
|
test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
|
|
git config diff.mnemonicprefix true &&
|
|
git commit --amend -v &&
|
|
check_message message &&
|
|
test_line_count = 1 out
|
|
'
|
|
|
|
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_expect_success 'status does not verbose without --verbose' '
|
|
git status >actual &&
|
|
! grep "^diff --git" actual
|
|
'
|
|
|
|
test_done
|