3 # Copyright (c) 2006 Eric Wong
6 test_description
='git rebase --merge --skip tests'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 .
"$TEST_DIRECTORY"/lib-rebase.sh
16 # we assume the default git am -3 --skip strategy is tested independently
19 test_expect_success setup
'
22 git commit -m "hello" &&
23 git branch skip-reference &&
26 echo world >> hello &&
27 git commit -a -m "hello world" &&
28 echo goodbye >> hello &&
29 git commit -a -m "goodbye" &&
32 git checkout --detach &&
33 git checkout HEAD^ . &&
35 git commit -m reverted-goodbye &&
36 git tag reverted-goodbye &&
37 git checkout goodbye &&
39 GIT_AUTHOR_NAME="Another Author" \
40 GIT_AUTHOR_EMAIL="another.author@example.com" \
41 git commit --amend --no-edit -m amended-goodbye \
44 git tag amended-goodbye &&
46 git checkout -f skip-reference &&
48 git commit -a -m "we should skip this" &&
51 git commit -m "this should not be skipped" &&
52 git branch pre-rebase skip-reference &&
53 git branch skip-merge skip-reference
56 test_expect_success
'rebase with git am -3 (default)' '
57 test_must_fail git rebase --apply main
60 test_expect_success
'rebase --skip can not be used with other options' '
61 test_must_fail git rebase -v --skip &&
62 test_must_fail git rebase --skip -v
65 test_expect_success
'rebase --skip with am -3' '
69 test_expect_success
'rebase moves back to skip-reference' '
70 test refs/heads/skip-reference = $(git symbolic-ref HEAD) &&
71 git branch post-rebase &&
72 git reset --hard pre-rebase &&
73 test_must_fail git rebase main &&
74 echo "hello" > hello &&
76 git rebase --continue &&
77 test refs/heads/skip-reference = $(git symbolic-ref HEAD) &&
78 git reset --hard post-rebase
81 test_expect_success
'checkout skip-merge' 'git checkout -f skip-merge'
83 test_expect_success
'rebase with --merge' '
84 test_must_fail git rebase --merge main
87 test_expect_success
'rebase --skip with --merge' '
91 test_expect_success
'merge and reference trees equal' '
92 test -z "$(git diff-tree skip-merge skip-reference)"
95 test_expect_success
'moved back to branch correctly' '
96 test refs/heads/skip-merge = $(git symbolic-ref HEAD)
99 test_debug
'gitk --all & sleep 1'
101 test_expect_success
'skipping final pick removes .git/MERGE_MSG' '
102 test_must_fail git rebase --onto hello reverted-goodbye^ \
105 test_path_is_missing .git/MERGE_MSG
108 test_expect_success
'correct advice upon picking empty commit' '
109 test_when_finished "git rebase --abort" &&
110 test_must_fail git rebase -i --onto goodbye \
111 amended-goodbye^ amended-goodbye 2>err &&
112 test_grep "previous cherry-pick is now empty" err &&
113 test_grep "git rebase --skip" err &&
114 test_must_fail git commit &&
115 test_grep "git rebase --skip" err
118 test_expect_success
'correct authorship when committing empty pick' '
119 test_when_finished "git rebase --abort" &&
120 test_must_fail git rebase -i --onto goodbye \
121 amended-goodbye^ amended-goodbye &&
122 git commit --allow-empty &&
123 git log --pretty=format:"%an <%ae>%n%ad%B" -1 amended-goodbye >expect &&
124 git log --pretty=format:"%an <%ae>%n%ad%B" -1 HEAD >actual &&
125 test_cmp expect actual
128 test_expect_success
'correct advice upon rewording empty commit' '
129 test_when_finished "git rebase --abort" &&
132 test_must_fail env FAKE_LINES="reword 1" git rebase -i \
133 --onto goodbye amended-goodbye^ amended-goodbye 2>err
135 test_grep "previous cherry-pick is now empty" err &&
136 test_grep "git rebase --skip" err &&
137 test_must_fail git commit &&
138 test_grep "git rebase --skip" err
141 test_expect_success
'correct advice upon editing empty commit' '
142 test_when_finished "git rebase --abort" &&
145 test_must_fail env FAKE_LINES="edit 1" git rebase -i \
146 --onto goodbye amended-goodbye^ amended-goodbye 2>err
148 test_grep "previous cherry-pick is now empty" err &&
149 test_grep "git rebase --skip" err &&
150 test_must_fail git commit &&
151 test_grep "git rebase --skip" err
154 test_expect_success
'correct advice upon cherry-picking an empty commit during a rebase' '
155 test_when_finished "git rebase --abort" &&
158 test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_amended-goodbye" \
159 git rebase -i goodbye^ goodbye 2>err
161 test_grep "previous cherry-pick is now empty" err &&
162 test_grep "git cherry-pick --skip" err &&
163 test_must_fail git commit 2>err &&
164 test_grep "git cherry-pick --skip" err
167 test_expect_success
'correct advice upon multi cherry-pick picking an empty commit during a rebase' '
168 test_when_finished "git rebase --abort" &&
171 test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_goodbye_amended-goodbye" \
172 git rebase -i goodbye^^ goodbye 2>err
174 test_grep "previous cherry-pick is now empty" err &&
175 test_grep "git cherry-pick --skip" err &&
176 test_must_fail git commit 2>err &&
177 test_grep "git cherry-pick --skip" err
180 test_expect_success
'fixup that empties commit fails' '
181 test_when_finished "git rebase --abort" &&
184 test_must_fail env FAKE_LINES="1 fixup 2" git rebase -i \
185 goodbye^ reverted-goodbye
189 test_expect_success
'squash that empties commit fails' '
190 test_when_finished "git rebase --abort" &&
193 test_must_fail env FAKE_LINES="1 squash 2" git rebase -i \
194 goodbye^ reverted-goodbye
198 # Must be the last test in this file
199 test_expect_success
'$EDITOR and friends are unchanged' '
200 test_editor_unchanged