]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3432-rebase-fast-forward.sh
Merge branch 'al/ref-filter-merged-and-no-merged'
[thirdparty/git.git] / t / t3432-rebase-fast-forward.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Denton Liu
4 #
5
6 test_description='ensure rebase fast-forwards commits when possible'
7
8 . ./test-lib.sh
9
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
16 '
17
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" "$*"
37 }
38
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 git reflog HEAD >expect &&
64 git rebase$flag $* >stdout &&
65 git reflog HEAD >actual &&
66 if test $what = work
67 then
68 old=\$(wc -l <expect) &&
69 test_line_count '-gt' \$old actual
70 elif test $what = noop
71 then
72 test_cmp expect actual
73 fi &&
74 newhead=\$(git rev-parse HEAD) &&
75 if test $cmp = same
76 then
77 test_cmp_rev \$oldhead \$newhead
78 elif test $cmp = diff
79 then
80 test_cmp_rev ! \$oldhead \$newhead
81 fi
82 "
83 }
84
85 changes='no changes'
86 test_rebase_same_head success noop same success work same
87 test_rebase_same_head success noop same success work same master
88 test_rebase_same_head success noop same success work diff --onto B B
89 test_rebase_same_head success noop same success work diff --onto B... B
90 test_rebase_same_head success noop same success work same --onto master... master
91 test_rebase_same_head success noop same success work same --keep-base master
92 test_rebase_same_head success noop same success work same --keep-base
93 test_rebase_same_head success noop same success work same --no-fork-point
94 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
95 test_rebase_same_head success noop same success work same --fork-point master
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 diff --fork-point --onto B... B
98 test_rebase_same_head success noop same success work same --fork-point --onto master... master
99 test_rebase_same_head success noop same success work same --keep-base --keep-base master
100
101 test_expect_success 'add work same to side' '
102 test_commit E
103 '
104
105 changes='our changes'
106 test_rebase_same_head success noop same success work same
107 test_rebase_same_head success noop same success work same master
108 test_rebase_same_head success noop same success work diff --onto B B
109 test_rebase_same_head success noop same success work diff --onto B... B
110 test_rebase_same_head success noop same success work same --onto master... master
111 test_rebase_same_head success noop same success work same --keep-base master
112 test_rebase_same_head success noop same success work same --keep-base
113 test_rebase_same_head success noop same success work same --no-fork-point
114 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
115 test_rebase_same_head success noop same success work same --fork-point master
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 diff --fork-point --onto B... B
118 test_rebase_same_head success noop same success work same --fork-point --onto master... master
119 test_rebase_same_head success noop same success work same --fork-point --keep-base master
120
121 test_expect_success 'add work same to upstream' '
122 git checkout master &&
123 test_commit F &&
124 git checkout side
125 '
126
127 changes='our and their changes'
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 B... B
130 test_rebase_same_head success noop same success work diff --onto master... master
131 test_rebase_same_head success noop same success work diff --keep-base master
132 test_rebase_same_head success noop same success work diff --keep-base
133 test_rebase_same_head failure work same success work diff --fork-point --onto B B
134 test_rebase_same_head failure work same success work diff --fork-point --onto B... B
135 test_rebase_same_head success noop same success work diff --fork-point --onto master... master
136 test_rebase_same_head success noop same success work diff --fork-point --keep-base master
137
138 test_done