3 # Copyright (c) 2019 Denton Liu
6 test_description='ensure rebase fast-forwards commits when possible'
10 test_expect_success setup '
15 git checkout -t -b side
18 test_rebase_same_head () {
31 test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --apply" "$*" &&
32 test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --apply --no-ff" "$*"
33 test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --merge" "$*" &&
34 test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --merge --no-ff" "$*"
35 test_rebase_same_head_ $status_n $what_n $cmp_n 1 " --merge" "$*" &&
36 test_rebase_same_head_ $status_f $what_f $cmp_f 1 " --merge --no-ff" "$*"
39 test_rebase_same_head_ () {
50 if test $abbreviate -eq 1
52 msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
54 msg="git rebase$flag $* with $changes is $what with $cmp HEAD"
56 test_expect_$status "$msg" "
57 if test $abbreviate -eq 1
59 test_config rebase.abbreviateCommands true
61 oldhead=\$(git rev-parse HEAD) &&
62 test_when_finished 'git reset --hard \$oldhead' &&
63 cp .git/logs/HEAD expect &&
64 git rebase$flag $* >stdout &&
67 old=\$(wc -l <expect) &&
68 test_line_count '-gt' \$old .git/logs/HEAD
69 elif test $what = noop
71 test_cmp expect .git/logs/HEAD
73 newhead=\$(git rev-parse HEAD) &&
76 test_cmp_rev \$oldhead \$newhead
79 test_cmp_rev ! \$oldhead \$newhead
85 test_rebase_same_head success noop same success work same
86 test_rebase_same_head success noop same success work same master
87 test_rebase_same_head success noop same success work diff --onto B B
88 test_rebase_same_head success noop same success work diff --onto B... B
89 test_rebase_same_head success noop same success work same --onto master... master
90 test_rebase_same_head success noop same success work same --keep-base master
91 test_rebase_same_head success noop same success work same --keep-base
92 test_rebase_same_head success noop same success work same --no-fork-point
93 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
94 test_rebase_same_head success noop same success work same --fork-point master
95 test_rebase_same_head success noop same success work diff --fork-point --onto B B
96 test_rebase_same_head success noop same success work diff --fork-point --onto B... B
97 test_rebase_same_head success noop same success work same --fork-point --onto master... master
98 test_rebase_same_head success noop same success work same --keep-base --keep-base master
100 test_expect_success 'add work same to side' '
104 changes='our changes'
105 test_rebase_same_head success noop same success work same
106 test_rebase_same_head success noop same success work same master
107 test_rebase_same_head success noop same success work diff --onto B B
108 test_rebase_same_head success noop same success work diff --onto B... B
109 test_rebase_same_head success noop same success work same --onto master... master
110 test_rebase_same_head success noop same success work same --keep-base master
111 test_rebase_same_head success noop same success work same --keep-base
112 test_rebase_same_head success noop same success work same --no-fork-point
113 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
114 test_rebase_same_head success noop same success work same --fork-point master
115 test_rebase_same_head success noop same success work diff --fork-point --onto B B
116 test_rebase_same_head success noop same success work diff --fork-point --onto B... B
117 test_rebase_same_head success noop same success work same --fork-point --onto master... master
118 test_rebase_same_head success noop same success work same --fork-point --keep-base master
120 test_expect_success 'add work same to upstream' '
121 git checkout master &&
126 changes='our and their changes'
127 test_rebase_same_head success noop same success work diff --onto B B
128 test_rebase_same_head success noop same success work diff --onto B... B
129 test_rebase_same_head success noop same success work diff --onto master... master
130 test_rebase_same_head success noop same success work diff --keep-base master
131 test_rebase_same_head success noop same success work diff --keep-base
132 test_rebase_same_head failure work same success work diff --fork-point --onto B B
133 test_rebase_same_head failure work same success work diff --fork-point --onto B... B
134 test_rebase_same_head success noop same success work diff --fork-point --onto master... master
135 test_rebase_same_head success noop same success work diff --fork-point --keep-base master