3 # Copyright (c) 2019 Denton Liu
6 test_description
='ensure rebase fast-forwards commits when possible'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 test_expect_success setup
'
19 git checkout -t -b side
22 test_rebase_same_head
() {
35 test_rebase_same_head_
$status_n $what_n $cmp_n 0 " --apply" "$*" &&
36 test_rebase_same_head_
$status_f $what_f $cmp_f 0 " --apply --no-ff" "$*"
37 test_rebase_same_head_
$status_n $what_n $cmp_n 0 " --merge" "$*" &&
38 test_rebase_same_head_
$status_f $what_f $cmp_f 0 " --merge --no-ff" "$*"
39 test_rebase_same_head_
$status_n $what_n $cmp_n 1 " --merge" "$*" &&
40 test_rebase_same_head_
$status_f $what_f $cmp_f 1 " --merge --no-ff" "$*"
43 test_rebase_same_head_
() {
54 if test $abbreviate -eq 1
56 msg
="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
58 msg
="git rebase$flag $* with $changes is $what with $cmp HEAD"
60 test_expect_
$status "$msg" "
61 if test $abbreviate -eq 1
63 test_config rebase.abbreviateCommands true
65 oldhead=\$(git rev-parse HEAD) &&
66 test_when_finished 'git reset --hard \$oldhead' &&
67 git reflog HEAD >expect &&
68 git rebase$flag $* >stdout &&
69 git reflog HEAD >actual &&
72 old=\$(wc -l <expect) &&
73 test_line_count '-gt' \$old actual
74 elif test $what = noop
76 test_cmp expect actual
78 newhead=\$(git rev-parse HEAD) &&
81 test_cmp_rev \$oldhead \$newhead
84 test_cmp_rev ! \$oldhead \$newhead
90 test_rebase_same_head success noop same success work same
91 test_rebase_same_head success noop same success work same main
92 test_rebase_same_head success noop same success work
diff --onto B B
93 test_rebase_same_head success noop same success work
diff --onto B... B
94 test_rebase_same_head success noop same success work same
--onto main... main
95 test_rebase_same_head success noop same success work same
--keep-base main
96 test_rebase_same_head success noop same success work same
--keep-base
97 test_rebase_same_head success noop same success work same
--no-fork-point
98 test_rebase_same_head success noop same success work same
--keep-base --no-fork-point
99 test_rebase_same_head success noop same success work same
--fork-point main
100 test_rebase_same_head success noop same success work
diff --fork-point --onto B B
101 test_rebase_same_head success noop same success work
diff --fork-point --onto B... B
102 test_rebase_same_head success noop same success work same
--fork-point --onto main... main
103 test_rebase_same_head success noop same success work same
--keep-base --keep-base main
105 test_expect_success
'add work same to side' '
109 changes
='our changes'
110 test_rebase_same_head success noop same success work same
111 test_rebase_same_head success noop same success work same main
112 test_rebase_same_head success noop same success work
diff --onto B B
113 test_rebase_same_head success noop same success work
diff --onto B... B
114 test_rebase_same_head success noop same success work same
--onto main... main
115 test_rebase_same_head success noop same success work same
--keep-base main
116 test_rebase_same_head success noop same success work same
--keep-base
117 test_rebase_same_head success noop same success work same
--no-fork-point
118 test_rebase_same_head success noop same success work same
--keep-base --no-fork-point
119 test_rebase_same_head success noop same success work same
--fork-point main
120 test_rebase_same_head success noop same success work
diff --fork-point --onto B B
121 test_rebase_same_head success noop same success work
diff --fork-point --onto B... B
122 test_rebase_same_head success noop same success work same
--fork-point --onto main... main
123 test_rebase_same_head success noop same success work same
--fork-point --keep-base main
125 test_expect_success
'add work same to upstream' '
131 changes
='our and their changes'
132 test_rebase_same_head success noop same success work
diff --onto B B
133 test_rebase_same_head success noop same success work
diff --onto B... B
134 test_rebase_same_head success noop same success work
diff --onto main... main
135 test_rebase_same_head success noop same success work
diff --keep-base main
136 test_rebase_same_head success noop same success work
diff --keep-base
137 test_rebase_same_head failure work same success work
diff --fork-point --onto B B
138 test_rebase_same_head failure work same success work
diff --fork-point --onto B... B
139 test_rebase_same_head success noop same success work
diff --fork-point --onto main... main
140 test_rebase_same_head success noop same success work
diff --fork-point --keep-base main