Git fork
1#!/bin/sh
2
3test_description='verbose commit template'
4
5. ./test-lib.sh
6
7write_script "check-for-diff" <<\EOF &&
8grep '^diff --git' "$1" >out
9exit 0
10EOF
11test_set_editor "$PWD/check-for-diff"
12
13cat >message <<'EOF'
14subject
15
16body
17EOF
18
19test_expect_success 'setup' '
20 echo content >file &&
21 git add file &&
22 git commit -F message
23'
24
25test_expect_success 'initial commit shows verbose diff' '
26 git commit --amend -v &&
27 test_line_count = 1 out
28'
29
30test_expect_success 'second commit' '
31 echo content modified >file &&
32 git add file &&
33 git commit -F message
34'
35
36check_message() {
37 git log -1 --pretty=format:%s%n%n%b >actual &&
38 test_cmp "$1" actual
39}
40
41test_expect_success 'verbose diff is stripped out' '
42 git commit --amend -v &&
43 check_message message &&
44 test_line_count = 1 out
45'
46
47test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
48 git config diff.mnemonicprefix true &&
49 git commit --amend -v &&
50 check_message message &&
51 test_line_count = 1 out
52'
53
54cat >diff <<'EOF'
55This is an example commit message that contains a diff.
56
57diff --git c/file i/file
58new file mode 100644
59index 0000000..f95c11d
60--- /dev/null
61+++ i/file
62@@ -0,0 +1 @@
63+this is some content
64EOF
65
66test_expect_success 'diff in message is retained without -v' '
67 git commit --amend -F diff &&
68 check_message diff
69'
70
71test_expect_success 'diff in message is retained with -v' '
72 git commit --amend -F diff -v &&
73 check_message diff
74'
75
76test_expect_success 'submodule log is stripped out too with -v' '
77 git config diff.submodule log &&
78 test_config_global protocol.file.allow always &&
79 git submodule add ./. sub &&
80 git commit -m "sub added" &&
81 (
82 cd sub &&
83 echo "more" >>file &&
84 git commit -a -m "submodule commit"
85 ) &&
86 (
87 GIT_EDITOR=cat &&
88 export GIT_EDITOR &&
89 test_must_fail git commit -a -v 2>err
90 ) &&
91 test_grep "Aborting commit due to empty commit message." err
92'
93
94test_expect_success 'verbose diff is stripped out with set core.commentChar' '
95 (
96 GIT_EDITOR=cat &&
97 export GIT_EDITOR &&
98 test_must_fail git -c core.commentchar=";" commit -a -v 2>err
99 ) &&
100 test_grep "Aborting commit due to empty commit message." err
101'
102
103test_expect_success 'verbose diff is stripped with multi-byte comment char' '
104 (
105 GIT_EDITOR=cat &&
106 export GIT_EDITOR &&
107 test_must_fail git -c core.commentchar="foo>" commit -a -v >out 2>err
108 ) &&
109 grep "^foo> " out &&
110 test_grep "Aborting commit due to empty commit message." err
111'
112
113test_expect_success 'status does not verbose without --verbose' '
114 git status >actual &&
115 ! grep "^diff --git" actual
116'
117
118test_expect_success 'setup -v -v' '
119 echo dirty >file
120'
121
122for i in true 1
123do
124 test_expect_success "commit.verbose=$i and --verbose omitted" "
125 git -c commit.verbose=$i commit --amend &&
126 test_line_count = 1 out
127 "
128done
129
130for i in false -2 -1 0
131do
132 test_expect_success "commit.verbose=$i and --verbose omitted" "
133 git -c commit.verbose=$i commit --amend &&
134 test_line_count = 0 out
135 "
136done
137
138for i in 2 3
139do
140 test_expect_success "commit.verbose=$i and --verbose omitted" "
141 git -c commit.verbose=$i commit --amend &&
142 test_line_count = 2 out
143 "
144done
145
146for i in true false -2 -1 0 1 2 3
147do
148 test_expect_success "commit.verbose=$i and --verbose" "
149 git -c commit.verbose=$i commit --amend --verbose &&
150 test_line_count = 1 out
151 "
152
153 test_expect_success "commit.verbose=$i and --no-verbose" "
154 git -c commit.verbose=$i commit --amend --no-verbose &&
155 test_line_count = 0 out
156 "
157
158 test_expect_success "commit.verbose=$i and -v -v" "
159 git -c commit.verbose=$i commit --amend -v -v &&
160 test_line_count = 2 out
161 "
162done
163
164test_expect_success "status ignores commit.verbose=true" '
165 git -c commit.verbose=true status >actual &&
166 ! grep "^diff --git actual"
167'
168
169test_done