]>
Commit | Line | Data |
---|---|---|
793ac7e3 DL |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2019 Denton Liu | |
4 | # | |
5 | ||
6 | test_description='ensure rebase fast-forwards commits when possible' | |
7 | ||
d1c02d93 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
0c10ed19 | 11 | TEST_PASSES_SANITIZE_LEAK=true |
793ac7e3 DL |
12 | . ./test-lib.sh |
13 | ||
14 | test_expect_success setup ' | |
15 | test_commit A && | |
16 | test_commit B && | |
17 | test_commit C && | |
18 | test_commit D && | |
19 | git checkout -t -b side | |
20 | ' | |
21 | ||
22 | test_rebase_same_head () { | |
c9efc216 ÆAB |
23 | status_n="$1" && |
24 | shift && | |
25 | what_n="$1" && | |
26 | shift && | |
27 | cmp_n="$1" && | |
28 | shift && | |
29 | status_f="$1" && | |
30 | shift && | |
31 | what_f="$1" && | |
32 | shift && | |
33 | cmp_f="$1" && | |
34 | shift && | |
de9f1d3e AG |
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" "$*" | |
c9efc216 ÆAB |
41 | } |
42 | ||
43 | test_rebase_same_head_ () { | |
793ac7e3 DL |
44 | status="$1" && |
45 | shift && | |
4336d365 ÆAB |
46 | what="$1" && |
47 | shift && | |
48 | cmp="$1" && | |
49 | shift && | |
de9f1d3e AG |
50 | abbreviate="$1" && |
51 | shift && | |
c9efc216 ÆAB |
52 | flag="$1" |
53 | shift && | |
de9f1d3e AG |
54 | if test $abbreviate -eq 1 |
55 | then | |
56 | msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD" | |
57 | else | |
58 | msg="git rebase$flag $* with $changes is $what with $cmp HEAD" | |
59 | fi && | |
60 | test_expect_$status "$msg" " | |
61 | if test $abbreviate -eq 1 | |
62 | then | |
63 | test_config rebase.abbreviateCommands true | |
64 | fi && | |
793ac7e3 DL |
65 | oldhead=\$(git rev-parse HEAD) && |
66 | test_when_finished 'git reset --hard \$oldhead' && | |
ce57d856 | 67 | git reflog HEAD >expect && |
c9efc216 | 68 | git rebase$flag $* >stdout && |
ce57d856 | 69 | git reflog HEAD >actual && |
4336d365 ÆAB |
70 | if test $what = work |
71 | then | |
9a70f3d4 | 72 | old=\$(wc -l <expect) && |
ce57d856 | 73 | test_line_count '-gt' \$old actual |
4336d365 ÆAB |
74 | elif test $what = noop |
75 | then | |
ce57d856 | 76 | test_cmp expect actual |
4336d365 | 77 | fi && |
793ac7e3 | 78 | newhead=\$(git rev-parse HEAD) && |
4336d365 ÆAB |
79 | if test $cmp = same |
80 | then | |
81 | test_cmp_rev \$oldhead \$newhead | |
82 | elif test $cmp = diff | |
83 | then | |
2c9e125b | 84 | test_cmp_rev ! \$oldhead \$newhead |
4336d365 | 85 | fi |
793ac7e3 DL |
86 | " |
87 | } | |
88 | ||
89 | changes='no changes' | |
4effc5bc | 90 | test_rebase_same_head success noop same success work same |
d1c02d93 | 91 | test_rebase_same_head success noop same success work same main |
9a70f3d4 EN |
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 | |
d1c02d93 JS |
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 | |
9a70f3d4 EN |
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 | |
d1c02d93 | 99 | test_rebase_same_head success noop same success work same --fork-point main |
4effc5bc DL |
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 | |
d1c02d93 JS |
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 | |
793ac7e3 | 104 | |
4336d365 | 105 | test_expect_success 'add work same to side' ' |
793ac7e3 DL |
106 | test_commit E |
107 | ' | |
108 | ||
109 | changes='our changes' | |
4effc5bc | 110 | test_rebase_same_head success noop same success work same |
d1c02d93 | 111 | test_rebase_same_head success noop same success work same main |
9a70f3d4 EN |
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 | |
d1c02d93 JS |
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 | |
9a70f3d4 EN |
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 | |
d1c02d93 | 119 | test_rebase_same_head success noop same success work same --fork-point main |
4effc5bc DL |
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 | |
d1c02d93 JS |
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 | |
793ac7e3 | 124 | |
4336d365 | 125 | test_expect_success 'add work same to upstream' ' |
d1c02d93 | 126 | git checkout main && |
793ac7e3 DL |
127 | test_commit F && |
128 | git checkout side | |
129 | ' | |
130 | ||
131 | changes='our and their changes' | |
9a70f3d4 EN |
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 | |
d1c02d93 JS |
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 | |
414d924b | 136 | test_rebase_same_head success noop same success work diff --keep-base |
c9efc216 ÆAB |
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 | |
d1c02d93 JS |
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 | |
793ac7e3 DL |
141 | |
142 | test_done |