rebase: teach rebase --keep-base
[git/git.git] / t / t3432-rebase-fast-forward.sh
CommitLineData
793ac7e3
DL
1#!/bin/sh
2#
3# Copyright (c) 2019 Denton Liu
4#
5
6test_description='ensure rebase fast-forwards commits when possible'
7
8. ./test-lib.sh
9
10test_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
18test_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 &&
31 test_rebase_same_head_ $status_n $what_n $cmp_n "" "$*" &&
32 test_rebase_same_head_ $status_f $what_f $cmp_f " --no-ff" "$*"
33}
34
35test_rebase_same_head_ () {
793ac7e3
DL
36 status="$1" &&
37 shift &&
4336d365
ÆAB
38 what="$1" &&
39 shift &&
40 cmp="$1" &&
41 shift &&
c9efc216
ÆAB
42 flag="$1"
43 shift &&
44 test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
793ac7e3
DL
45 oldhead=\$(git rev-parse HEAD) &&
46 test_when_finished 'git reset --hard \$oldhead' &&
c9efc216 47 git rebase$flag $* >stdout &&
4336d365
ÆAB
48 if test $what = work
49 then
c9efc216
ÆAB
50 # Must check this case first, for 'is up to
51 # date, rebase forced[...]rewinding head' cases
4336d365
ÆAB
52 test_i18ngrep 'rewinding head' stdout
53 elif test $what = noop
54 then
c9efc216
ÆAB
55 test_i18ngrep 'is up to date' stdout &&
56 test_i18ngrep ! 'rebase forced' stdout
57 elif test $what = noop-force
58 then
59 test_i18ngrep 'is up to date, rebase forced' stdout
4336d365 60 fi &&
793ac7e3 61 newhead=\$(git rev-parse HEAD) &&
4336d365
ÆAB
62 if test $cmp = same
63 then
64 test_cmp_rev \$oldhead \$newhead
65 elif test $cmp = diff
66 then
67 ! test_cmp_rev \$oldhead \$newhead
68 fi
793ac7e3
DL
69 "
70}
71
72changes='no changes'
4effc5bc 73test_rebase_same_head success noop same success work same
c9efc216
ÆAB
74test_rebase_same_head success noop same success noop-force same master
75test_rebase_same_head success noop same success noop-force diff --onto B B
76test_rebase_same_head success noop same success noop-force diff --onto B... B
77test_rebase_same_head success noop same success noop-force same --onto master... master
414d924b
DL
78test_rebase_same_head success noop same success noop-force same --keep-base master
79test_rebase_same_head success noop same success noop-force same --keep-base
c9efc216 80test_rebase_same_head success noop same success noop-force same --no-fork-point
414d924b 81test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
4effc5bc
DL
82test_rebase_same_head success noop same success work same --fork-point master
83test_rebase_same_head success noop same success work diff --fork-point --onto B B
84test_rebase_same_head success noop same success work diff --fork-point --onto B... B
85test_rebase_same_head success noop same success work same --fork-point --onto master... master
414d924b 86test_rebase_same_head success noop same success work same --keep-base --keep-base master
793ac7e3 87
4336d365 88test_expect_success 'add work same to side' '
793ac7e3
DL
89 test_commit E
90'
91
92changes='our changes'
4effc5bc 93test_rebase_same_head success noop same success work same
c9efc216
ÆAB
94test_rebase_same_head success noop same success noop-force same master
95test_rebase_same_head success noop same success noop-force diff --onto B B
96test_rebase_same_head success noop same success noop-force diff --onto B... B
97test_rebase_same_head success noop same success noop-force same --onto master... master
414d924b
DL
98test_rebase_same_head success noop same success noop-force same --keep-base master
99test_rebase_same_head success noop same success noop-force same --keep-base
c9efc216 100test_rebase_same_head success noop same success noop-force same --no-fork-point
414d924b 101test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
4effc5bc
DL
102test_rebase_same_head success noop same success work same --fork-point master
103test_rebase_same_head success noop same success work diff --fork-point --onto B B
104test_rebase_same_head success noop same success work diff --fork-point --onto B... B
105test_rebase_same_head success noop same success work same --fork-point --onto master... master
414d924b 106test_rebase_same_head success noop same success work same --fork-point --keep-base master
793ac7e3 107
4336d365 108test_expect_success 'add work same to upstream' '
793ac7e3
DL
109 git checkout master &&
110 test_commit F &&
111 git checkout side
112'
113
114changes='our and their changes'
c9efc216
ÆAB
115test_rebase_same_head success noop same success noop-force diff --onto B B
116test_rebase_same_head success noop same success noop-force diff --onto B... B
c0efb4c1 117test_rebase_same_head success noop same success work diff --onto master... master
414d924b
DL
118test_rebase_same_head success noop same success work diff --keep-base master
119test_rebase_same_head success noop same success work diff --keep-base
c9efc216
ÆAB
120test_rebase_same_head failure work same success work diff --fork-point --onto B B
121test_rebase_same_head failure work same success work diff --fork-point --onto B... B
c0efb4c1 122test_rebase_same_head success noop same success work diff --fork-point --onto master... master
414d924b 123test_rebase_same_head success noop same success work diff --fork-point --keep-base master
793ac7e3
DL
124
125test_done