]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7507-commit-verbose.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t7507-commit-verbose.sh
CommitLineData
0b38227f
JK
1#!/bin/sh
2
3test_description='verbose commit template'
e77b3da6
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
0b38227f
JK
6. ./test-lib.sh
7
de45dbb8
PB
8write_script "check-for-diff" <<\EOF &&
9grep '^diff --git' "$1" >out
10exit 0
0b38227f 11EOF
0b38227f
JK
12test_set_editor "$PWD/check-for-diff"
13
14cat >message <<'EOF'
15subject
16
17body
18EOF
19
20test_expect_success 'setup' '
21 echo content >file &&
22 git add file &&
23 git commit -F message
24'
25
1324fb6f 26test_expect_success 'initial commit shows verbose diff' '
de45dbb8
PB
27 git commit --amend -v &&
28 test_line_count = 1 out
0b38227f
JK
29'
30
31test_expect_success 'second commit' '
32 echo content modified >file &&
33 git add file &&
34 git commit -F message
35'
36
37check_message() {
38 git log -1 --pretty=format:%s%n%n%b >actual &&
39 test_cmp "$1" actual
40}
41
42test_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
48test_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
55cat >diff <<'EOF'
56This is an example commit message that contains a diff.
57
58diff --git c/file i/file
59new file mode 100644
60index 0000000..f95c11d
61--- /dev/null
62+++ i/file
63@@ -0,0 +1 @@
64+this is some content
65EOF
66
67test_expect_success 'diff in message is retained without -v' '
68 git commit --amend -F diff &&
69 check_message diff
70'
71
1a72cfd7 72test_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
77test_expect_success 'submodule log is stripped out too with -v' '
78 git config diff.submodule log &&
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_i18ngrep "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_i18ngrep "Aborting commit due to empty commit message." err
101'
102
98baeb79
PB
103test_expect_success 'status does not verbose without --verbose' '
104 git status >actual &&
105 ! grep "^diff --git" actual
106'
107
aaab8420
PB
108test_expect_success 'setup -v -v' '
109 echo dirty >file
110'
111
112for i in true 1
113do
114 test_expect_success "commit.verbose=$i and --verbose omitted" "
115 git -c commit.verbose=$i commit --amend &&
116 test_line_count = 1 out
117 "
118done
119
120for i in false -2 -1 0
121do
122 test_expect_success "commit.verbose=$i and --verbose omitted" "
123 git -c commit.verbose=$i commit --amend &&
124 test_line_count = 0 out
125 "
126done
127
128for i in 2 3
129do
130 test_expect_success "commit.verbose=$i and --verbose omitted" "
131 git -c commit.verbose=$i commit --amend &&
132 test_line_count = 2 out
133 "
134done
135
136for i in true false -2 -1 0 1 2 3
137do
138 test_expect_success "commit.verbose=$i and --verbose" "
139 git -c commit.verbose=$i commit --amend --verbose &&
140 test_line_count = 1 out
141 "
142
143 test_expect_success "commit.verbose=$i and --no-verbose" "
144 git -c commit.verbose=$i commit --amend --no-verbose &&
145 test_line_count = 0 out
146 "
147
148 test_expect_success "commit.verbose=$i and -v -v" "
149 git -c commit.verbose=$i commit --amend -v -v &&
150 test_line_count = 2 out
151 "
152done
153
154test_expect_success "status ignores commit.verbose=true" '
155 git -c commit.verbose=true status >actual &&
156 ! grep "^diff --git actual"
157'
158
0b38227f 159test_done