]>
Commit | Line | Data |
---|---|---|
f59baa50 NS |
1 | #!/bin/sh |
2 | ||
3 | test_description='auto squash' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | echo 0 >file0 && | |
9 | git add . && | |
10 | test_tick && | |
11 | git commit -m "initial commit" && | |
12 | echo 0 >file1 && | |
13 | echo 2 >file2 && | |
14 | git add . && | |
15 | test_tick && | |
16 | git commit -m "first commit" && | |
b1a6c0a9 | 17 | git tag first-commit && |
f59baa50 NS |
18 | echo 3 >file3 && |
19 | git add . && | |
20 | test_tick && | |
21 | git commit -m "second commit" && | |
22 | git tag base | |
23 | ' | |
24 | ||
b1a6c0a9 | 25 | test_auto_fixup () { |
f59baa50 NS |
26 | git reset --hard base && |
27 | echo 1 >file1 && | |
28 | git add -u && | |
29 | test_tick && | |
7c6eafa3 | 30 | git commit -m "fixup! first" && |
f59baa50 | 31 | |
dd1e5b31 | 32 | git tag $1 && |
f59baa50 | 33 | test_tick && |
dd1e5b31 | 34 | git rebase $2 -i HEAD^^^ && |
f59baa50 | 35 | git log --oneline >actual && |
3fb0459b | 36 | test_line_count = 3 actual && |
dd1e5b31 | 37 | git diff --exit-code $1 && |
f59baa50 NS |
38 | test 1 = "$(git cat-file blob HEAD^:file1)" && |
39 | test 1 = $(git cat-file commit HEAD^ | grep first | wc -l) | |
dd1e5b31 HV |
40 | } |
41 | ||
42 | test_expect_success 'auto fixup (option)' ' | |
43 | test_auto_fixup final-fixup-option --autosquash | |
44 | ' | |
45 | ||
46 | test_expect_success 'auto fixup (config)' ' | |
47 | git config rebase.autosquash true && | |
48 | test_auto_fixup final-fixup-config-true && | |
49 | test_must_fail test_auto_fixup fixup-config-true-no --no-autosquash && | |
50 | git config rebase.autosquash false && | |
51 | test_must_fail test_auto_fixup final-fixup-config-false | |
f59baa50 NS |
52 | ' |
53 | ||
b1a6c0a9 | 54 | test_auto_squash () { |
f59baa50 NS |
55 | git reset --hard base && |
56 | echo 1 >file1 && | |
57 | git add -u && | |
58 | test_tick && | |
7c6eafa3 | 59 | git commit -m "squash! first" && |
f59baa50 | 60 | |
dd1e5b31 | 61 | git tag $1 && |
f59baa50 | 62 | test_tick && |
dd1e5b31 | 63 | git rebase $2 -i HEAD^^^ && |
f59baa50 | 64 | git log --oneline >actual && |
3fb0459b | 65 | test_line_count = 3 actual && |
dd1e5b31 | 66 | git diff --exit-code $1 && |
f59baa50 NS |
67 | test 1 = "$(git cat-file blob HEAD^:file1)" && |
68 | test 2 = $(git cat-file commit HEAD^ | grep first | wc -l) | |
dd1e5b31 HV |
69 | } |
70 | ||
71 | test_expect_success 'auto squash (option)' ' | |
72 | test_auto_squash final-squash --autosquash | |
73 | ' | |
74 | ||
75 | test_expect_success 'auto squash (config)' ' | |
76 | git config rebase.autosquash true && | |
77 | test_auto_squash final-squash-config-true && | |
78 | test_must_fail test_auto_squash squash-config-true-no --no-autosquash && | |
79 | git config rebase.autosquash false && | |
80 | test_must_fail test_auto_squash final-squash-config-false | |
f59baa50 NS |
81 | ' |
82 | ||
83 | test_expect_success 'misspelled auto squash' ' | |
84 | git reset --hard base && | |
85 | echo 1 >file1 && | |
86 | git add -u && | |
87 | test_tick && | |
7c6eafa3 | 88 | git commit -m "squash! forst" && |
f59baa50 NS |
89 | git tag final-missquash && |
90 | test_tick && | |
91 | git rebase --autosquash -i HEAD^^^ && | |
92 | git log --oneline >actual && | |
3fb0459b | 93 | test_line_count = 4 actual && |
f59baa50 NS |
94 | git diff --exit-code final-missquash && |
95 | test 0 = $(git rev-list final-missquash...HEAD | wc -l) | |
96 | ' | |
97 | ||
d3d7a421 KB |
98 | test_expect_success 'auto squash that matches 2 commits' ' |
99 | git reset --hard base && | |
100 | echo 4 >file4 && | |
101 | git add file4 && | |
102 | test_tick && | |
103 | git commit -m "first new commit" && | |
104 | echo 1 >file1 && | |
105 | git add -u && | |
106 | test_tick && | |
107 | git commit -m "squash! first" && | |
108 | git tag final-multisquash && | |
109 | test_tick && | |
110 | git rebase --autosquash -i HEAD~4 && | |
111 | git log --oneline >actual && | |
3fb0459b | 112 | test_line_count = 4 actual && |
d3d7a421 KB |
113 | git diff --exit-code final-multisquash && |
114 | test 1 = "$(git cat-file blob HEAD^^:file1)" && | |
115 | test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) && | |
116 | test 1 = $(git cat-file commit HEAD | grep first | wc -l) | |
117 | ' | |
118 | ||
119 | test_expect_success 'auto squash that matches a commit after the squash' ' | |
120 | git reset --hard base && | |
121 | echo 1 >file1 && | |
122 | git add -u && | |
123 | test_tick && | |
124 | git commit -m "squash! third" && | |
125 | echo 4 >file4 && | |
126 | git add file4 && | |
127 | test_tick && | |
128 | git commit -m "third commit" && | |
129 | git tag final-presquash && | |
130 | test_tick && | |
131 | git rebase --autosquash -i HEAD~4 && | |
132 | git log --oneline >actual && | |
3fb0459b | 133 | test_line_count = 5 actual && |
d3d7a421 KB |
134 | git diff --exit-code final-presquash && |
135 | test 0 = "$(git cat-file blob HEAD^^:file1)" && | |
136 | test 1 = "$(git cat-file blob HEAD^:file1)" && | |
137 | test 1 = $(git cat-file commit HEAD | grep third | wc -l) && | |
138 | test 1 = $(git cat-file commit HEAD^ | grep third | wc -l) | |
139 | ' | |
68d5d03b KB |
140 | test_expect_success 'auto squash that matches a sha1' ' |
141 | git reset --hard base && | |
142 | echo 1 >file1 && | |
143 | git add -u && | |
144 | test_tick && | |
145 | git commit -m "squash! $(git rev-parse --short HEAD^)" && | |
146 | git tag final-shasquash && | |
147 | test_tick && | |
148 | git rebase --autosquash -i HEAD^^^ && | |
149 | git log --oneline >actual && | |
3fb0459b | 150 | test_line_count = 3 actual && |
68d5d03b KB |
151 | git diff --exit-code final-shasquash && |
152 | test 1 = "$(git cat-file blob HEAD^:file1)" && | |
153 | test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) | |
154 | ' | |
155 | ||
156 | test_expect_success 'auto squash that matches longer sha1' ' | |
157 | git reset --hard base && | |
158 | echo 1 >file1 && | |
159 | git add -u && | |
160 | test_tick && | |
161 | git commit -m "squash! $(git rev-parse --short=11 HEAD^)" && | |
162 | git tag final-longshasquash && | |
163 | test_tick && | |
164 | git rebase --autosquash -i HEAD^^^ && | |
165 | git log --oneline >actual && | |
3fb0459b | 166 | test_line_count = 3 actual && |
68d5d03b KB |
167 | git diff --exit-code final-longshasquash && |
168 | test 1 = "$(git cat-file blob HEAD^:file1)" && | |
169 | test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) | |
170 | ' | |
d3d7a421 | 171 | |
b1a6c0a9 PN |
172 | test_auto_commit_flags () { |
173 | git reset --hard base && | |
174 | echo 1 >file1 && | |
175 | git add -u && | |
176 | test_tick && | |
177 | git commit --$1 first-commit && | |
178 | git tag final-commit-$1 && | |
179 | test_tick && | |
180 | git rebase --autosquash -i HEAD^^^ && | |
181 | git log --oneline >actual && | |
3fb0459b | 182 | test_line_count = 3 actual && |
b1a6c0a9 PN |
183 | git diff --exit-code final-commit-$1 && |
184 | test 1 = "$(git cat-file blob HEAD^:file1)" && | |
185 | test $2 = $(git cat-file commit HEAD^ | grep first | wc -l) | |
186 | } | |
187 | ||
188 | test_expect_success 'use commit --fixup' ' | |
189 | test_auto_commit_flags fixup 1 | |
190 | ' | |
191 | ||
7951bd30 PN |
192 | test_expect_success 'use commit --squash' ' |
193 | test_auto_commit_flags squash 2 | |
194 | ' | |
195 | ||
f59baa50 | 196 | test_done |