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
13 test_expect_success setup
'
18 git checkout -t -b side
21 test_rebase_same_head
() {
34 test_rebase_same_head_
$status_n $what_n $cmp_n 0 " --apply" "$*" &&
35 test_rebase_same_head_
$status_f $what_f $cmp_f 0 " --apply --no-ff" "$*"
36 test_rebase_same_head_
$status_n $what_n $cmp_n 0 " --merge" "$*" &&
37 test_rebase_same_head_
$status_f $what_f $cmp_f 0 " --merge --no-ff" "$*"
38 test_rebase_same_head_
$status_n $what_n $cmp_n 1 " --merge" "$*" &&
39 test_rebase_same_head_
$status_f $what_f $cmp_f 1 " --merge --no-ff" "$*"
42 test_rebase_same_head_
() {
53 if test $abbreviate -eq 1
55 msg
="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
57 msg
="git rebase$flag $* with $changes is $what with $cmp HEAD"
59 test_expect_
$status "$msg" "
60 if test $abbreviate -eq 1
62 test_config rebase.abbreviateCommands true
64 oldhead=\$(git rev-parse HEAD) &&
65 test_when_finished 'git reset --hard \$oldhead' &&
66 git reflog HEAD >expect &&
67 git rebase$flag $* >stdout &&
68 git reflog HEAD >actual &&
71 old=\$(wc -l <expect) &&
72 test_line_count '-gt' \$old actual
73 elif test $what = noop
75 test_cmp expect actual
77 newhead=\$(git rev-parse HEAD) &&
80 test_cmp_rev \$oldhead \$newhead
83 test_cmp_rev ! \$oldhead \$newhead
89 test_rebase_same_head success noop same success work same
90 test_rebase_same_head success noop same success work same main
91 test_rebase_same_head success noop same success work
diff --onto B B
92 test_rebase_same_head success noop same success work
diff --onto B... B
93 test_rebase_same_head success noop same success work same
--onto main... main
94 test_rebase_same_head success noop same success work same
--keep-base main
95 test_rebase_same_head success noop same success work same
--keep-base
96 test_rebase_same_head success noop same success work same
--no-fork-point
97 test_rebase_same_head success noop same success work same
--keep-base --no-fork-point
98 test_rebase_same_head success noop same success work same
--fork-point main
99 test_rebase_same_head success noop same success work
diff --fork-point --onto B B
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 same
--fork-point --onto main... main
102 test_rebase_same_head success noop same success work same
--keep-base --keep-base main
104 test_expect_success
'add work same to side' '
108 changes
='our changes'
109 test_rebase_same_head success noop same success work same
110 test_rebase_same_head success noop same success work same main
111 test_rebase_same_head success noop same success work
diff --onto B B
112 test_rebase_same_head success noop same success work
diff --onto B... B
113 test_rebase_same_head success noop same success work same
--onto main... main
114 test_rebase_same_head success noop same success work same
--keep-base main
115 test_rebase_same_head success noop same success work same
--keep-base
116 test_rebase_same_head success noop same success work same
--no-fork-point
117 test_rebase_same_head success noop same success work same
--keep-base --no-fork-point
118 test_rebase_same_head success noop same success work same
--fork-point main
119 test_rebase_same_head success noop same success work
diff --fork-point --onto B B
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 same
--fork-point --onto main... main
122 test_rebase_same_head success noop same success work same
--fork-point --keep-base main
124 test_expect_success
'add work same to upstream' '
130 changes
='our and their changes'
131 test_rebase_same_head success noop same success work
diff --onto B B
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 main... main
134 test_rebase_same_head success noop same success work
diff --keep-base main
135 test_rebase_same_head success noop same success work
diff --keep-base
136 test_rebase_same_head failure work same success work
diff --fork-point --onto B B
137 test_rebase_same_head failure work same success work
diff --fork-point --onto B... B
138 test_rebase_same_head success noop same success work
diff --fork-point --onto main... main
139 test_rebase_same_head success noop same success work
diff --fork-point --keep-base main