]>
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 | ||
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 () { | |
c9efc216 ÆAB |
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 && | |
de9f1d3e AG |
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" "$*" | |
c9efc216 ÆAB |
37 | } |
38 | ||
39 | test_rebase_same_head_ () { | |
793ac7e3 DL |
40 | status="$1" && |
41 | shift && | |
4336d365 ÆAB |
42 | what="$1" && |
43 | shift && | |
44 | cmp="$1" && | |
45 | shift && | |
de9f1d3e AG |
46 | abbreviate="$1" && |
47 | shift && | |
c9efc216 ÆAB |
48 | flag="$1" |
49 | shift && | |
de9f1d3e AG |
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 && | |
793ac7e3 DL |
61 | oldhead=\$(git rev-parse HEAD) && |
62 | test_when_finished 'git reset --hard \$oldhead' && | |
9a70f3d4 | 63 | cp .git/logs/HEAD expect && |
c9efc216 | 64 | git rebase$flag $* >stdout && |
4336d365 ÆAB |
65 | if test $what = work |
66 | then | |
9a70f3d4 EN |
67 | old=\$(wc -l <expect) && |
68 | test_line_count '-gt' \$old .git/logs/HEAD | |
4336d365 ÆAB |
69 | elif test $what = noop |
70 | then | |
9a70f3d4 | 71 | test_cmp expect .git/logs/HEAD |
4336d365 | 72 | fi && |
793ac7e3 | 73 | newhead=\$(git rev-parse HEAD) && |
4336d365 ÆAB |
74 | if test $cmp = same |
75 | then | |
76 | test_cmp_rev \$oldhead \$newhead | |
77 | elif test $cmp = diff | |
78 | then | |
2c9e125b | 79 | test_cmp_rev ! \$oldhead \$newhead |
4336d365 | 80 | fi |
793ac7e3 DL |
81 | " |
82 | } | |
83 | ||
84 | changes='no changes' | |
4effc5bc | 85 | test_rebase_same_head success noop same success work same |
9a70f3d4 EN |
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 | |
4effc5bc DL |
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 | |
414d924b | 98 | test_rebase_same_head success noop same success work same --keep-base --keep-base master |
793ac7e3 | 99 | |
4336d365 | 100 | test_expect_success 'add work same to side' ' |
793ac7e3 DL |
101 | test_commit E |
102 | ' | |
103 | ||
104 | changes='our changes' | |
4effc5bc | 105 | test_rebase_same_head success noop same success work same |
9a70f3d4 EN |
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 | |
4effc5bc DL |
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 | |
414d924b | 118 | test_rebase_same_head success noop same success work same --fork-point --keep-base master |
793ac7e3 | 119 | |
4336d365 | 120 | test_expect_success 'add work same to upstream' ' |
793ac7e3 DL |
121 | git checkout master && |
122 | test_commit F && | |
123 | git checkout side | |
124 | ' | |
125 | ||
126 | changes='our and their changes' | |
9a70f3d4 EN |
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 | |
c0efb4c1 | 129 | test_rebase_same_head success noop same success work diff --onto master... master |
414d924b DL |
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 | |
c9efc216 ÆAB |
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 | |
c0efb4c1 | 134 | test_rebase_same_head success noop same success work diff --fork-point --onto master... master |
414d924b | 135 | test_rebase_same_head success noop same success work diff --fork-point --keep-base master |
793ac7e3 DL |
136 | |
137 | test_done |