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