3 test_description='auto squash'
7 test_expect_success setup '
11 git commit -m "initial commit" &&
16 git commit -m "first commit" &&
17 git tag first-commit &&
21 git commit -m "second commit" &&
26 git reset --hard base &&
30 git commit -m "fixup! first" &&
34 git rebase $2 -i HEAD^^^ &&
35 git log --oneline >actual &&
36 test 3 = $(wc -l <actual) &&
37 git diff --exit-code $1 &&
38 test 1 = "$(git cat-file blob HEAD^:file1)" &&
39 test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
42 test_expect_success 'auto fixup (option)' '
43 test_auto_fixup final-fixup-option --autosquash
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
55 git reset --hard base &&
59 git commit -m "squash! first" &&
63 git rebase $2 -i HEAD^^^ &&
64 git log --oneline >actual &&
65 test 3 = $(wc -l <actual) &&
66 git diff --exit-code $1 &&
67 test 1 = "$(git cat-file blob HEAD^:file1)" &&
68 test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
71 test_expect_success 'auto squash (option)' '
72 test_auto_squash final-squash --autosquash
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
83 test_expect_success 'misspelled auto squash' '
84 git reset --hard base &&
88 git commit -m "squash! forst" &&
89 git tag final-missquash &&
91 git rebase --autosquash -i HEAD^^^ &&
92 git log --oneline >actual &&
93 test 4 = $(wc -l <actual) &&
94 git diff --exit-code final-missquash &&
95 test 0 = $(git rev-list final-missquash...HEAD | wc -l)
98 test_expect_success 'auto squash that matches 2 commits' '
99 git reset --hard base &&
103 git commit -m "first new commit" &&
107 git commit -m "squash! first" &&
108 git tag final-multisquash &&
110 git rebase --autosquash -i HEAD~4 &&
111 git log --oneline >actual &&
112 test 4 = $(wc -l <actual) &&
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)
119 test_expect_success 'auto squash that matches a commit after the squash' '
120 git reset --hard base &&
124 git commit -m "squash! third" &&
128 git commit -m "third commit" &&
129 git tag final-presquash &&
131 git rebase --autosquash -i HEAD~4 &&
132 git log --oneline >actual &&
133 test 5 = $(wc -l <actual) &&
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)
140 test_expect_success 'auto squash that matches a sha1' '
141 git reset --hard base &&
145 git commit -m "squash! $(git rev-parse --short HEAD^)" &&
146 git tag final-shasquash &&
148 git rebase --autosquash -i HEAD^^^ &&
149 git log --oneline >actual &&
150 test 3 = $(wc -l <actual) &&
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)
156 test_expect_success 'auto squash that matches longer sha1' '
157 git reset --hard base &&
161 git commit -m "squash! $(git rev-parse --short=11 HEAD^)" &&
162 git tag final-longshasquash &&
164 git rebase --autosquash -i HEAD^^^ &&
165 git log --oneline >actual &&
166 test 3 = $(wc -l <actual) &&
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)
172 test_auto_commit_flags () {
173 git reset --hard base &&
177 git commit --$1 first-commit &&
178 git tag final-commit-$1 &&
180 git rebase --autosquash -i HEAD^^^ &&
181 git log --oneline >actual &&
182 test 3 = $(wc -l <actual) &&
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)
188 test_expect_success 'use commit --fixup' '
189 test_auto_commit_flags fixup 1
192 test_expect_success 'use commit --squash' '
193 test_auto_commit_flags squash 2