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