Merge branch 'dd/t5703-grep-a-fix'
[git.git] / t / t3432-rebase-fast-forward.sh
blob6f0452c0eac516796e27c5689b2e091c2b21b8ce
1 #!/bin/sh
3 # Copyright (c) 2019 Denton Liu
6 test_description='ensure rebase fast-forwards commits when possible'
8 . ./test-lib.sh
10 test_expect_success setup '
11 test_commit A &&
12 test_commit B &&
13 test_commit C &&
14 test_commit D &&
15 git checkout -t -b side
18 test_rebase_same_head () {
19 status_n="$1" &&
20 shift &&
21 what_n="$1" &&
22 shift &&
23 cmp_n="$1" &&
24 shift &&
25 status_f="$1" &&
26 shift &&
27 what_f="$1" &&
28 shift &&
29 cmp_f="$1" &&
30 shift &&
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_ () {
40 status="$1" &&
41 shift &&
42 what="$1" &&
43 shift &&
44 cmp="$1" &&
45 shift &&
46 abbreviate="$1" &&
47 shift &&
48 flag="$1"
49 shift &&
50 if test $abbreviate -eq 1
51 then
52 msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
53 else
54 msg="git rebase$flag $* with $changes is $what with $cmp HEAD"
55 fi &&
56 test_expect_$status "$msg" "
57 if test $abbreviate -eq 1
58 then
59 test_config rebase.abbreviateCommands true
60 fi &&
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 &&
65 if test $what = work
66 then
67 old=\$(wc -l <expect) &&
68 test_line_count '-gt' \$old .git/logs/HEAD
69 elif test $what = noop
70 then
71 test_cmp expect .git/logs/HEAD
72 fi &&
73 newhead=\$(git rev-parse HEAD) &&
74 if test $cmp = same
75 then
76 test_cmp_rev \$oldhead \$newhead
77 elif test $cmp = diff
78 then
79 test_cmp_rev ! \$oldhead \$newhead
84 changes='no changes'
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' '
101 test_commit E
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 &&
122 test_commit F &&
123 git checkout side
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
137 test_done