add tests of commit --squash
[git/jnareb-git.git] / t / t3415-rebase-autosquash.sh
blob0028533e0bfb544598ca6dc0de489bf9948b4eb4
1 #!/bin/sh
3 test_description='auto squash'
5 . ./test-lib.sh
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" &&
17 git tag first-commit &&
18 echo 3 >file3 &&
19 git add . &&
20 test_tick &&
21 git commit -m "second commit" &&
22 git tag base
25 test_auto_fixup () {
26 git reset --hard base &&
27 echo 1 >file1 &&
28 git add -u &&
29 test_tick &&
30 git commit -m "fixup! first" &&
32 git tag $1 &&
33 test_tick &&
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
54 test_auto_squash () {
55 git reset --hard base &&
56 echo 1 >file1 &&
57 git add -u &&
58 test_tick &&
59 git commit -m "squash! first" &&
61 git tag $1 &&
62 test_tick &&
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 &&
85 echo 1 >file1 &&
86 git add -u &&
87 test_tick &&
88 git commit -m "squash! forst" &&
89 git tag final-missquash &&
90 test_tick &&
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_auto_commit_flags () {
99 git reset --hard base &&
100 echo 1 >file1 &&
101 git add -u &&
102 test_tick &&
103 git commit --$1 first-commit &&
104 git tag final-commit-$1 &&
105 test_tick &&
106 git rebase --autosquash -i HEAD^^^ &&
107 git log --oneline >actual &&
108 test 3 = $(wc -l <actual) &&
109 git diff --exit-code final-commit-$1 &&
110 test 1 = "$(git cat-file blob HEAD^:file1)" &&
111 test $2 = $(git cat-file commit HEAD^ | grep first | wc -l)
114 test_expect_success 'use commit --fixup' '
115 test_auto_commit_flags fixup 1
118 test_expect_success 'use commit --squash' '
119 test_auto_commit_flags squash 2
122 test_done