Merge branch 'en/test-cleanup'
[alt-git.git] / t / t3432-rebase-fast-forward.sh
blob6c9d4a13758194dfcf4b005e36f8358ed5a27f80
1 #!/bin/sh
3 # Copyright (c) 2019 Denton Liu
6 test_description='ensure rebase fast-forwards commits when possible'
8 . ./test-lib.sh
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
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 " --apply" "$*" &&
32 test_rebase_same_head_ $status_f $what_f $cmp_f " --apply --no-ff" "$*"
33 test_rebase_same_head_ $status_n $what_n $cmp_n " --merge" "$*" &&
34 test_rebase_same_head_ $status_f $what_f $cmp_f " --merge --no-ff" "$*"
37 test_rebase_same_head_ () {
38 status="$1" &&
39 shift &&
40 what="$1" &&
41 shift &&
42 cmp="$1" &&
43 shift &&
44 flag="$1"
45 shift &&
46 test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
47 oldhead=\$(git rev-parse HEAD) &&
48 test_when_finished 'git reset --hard \$oldhead' &&
49 cp .git/logs/HEAD expect &&
50 git rebase$flag $* >stdout &&
51 if test $what = work
52 then
53 old=\$(wc -l <expect) &&
54 test_line_count '-gt' \$old .git/logs/HEAD
55 elif test $what = noop
56 then
57 test_cmp expect .git/logs/HEAD
58 fi &&
59 newhead=\$(git rev-parse HEAD) &&
60 if test $cmp = same
61 then
62 test_cmp_rev \$oldhead \$newhead
63 elif test $cmp = diff
64 then
65 test_cmp_rev ! \$oldhead \$newhead
70 changes='no changes'
71 test_rebase_same_head success noop same success work same
72 test_rebase_same_head success noop same success work same master
73 test_rebase_same_head success noop same success work diff --onto B B
74 test_rebase_same_head success noop same success work diff --onto B... B
75 test_rebase_same_head success noop same success work same --onto master... master
76 test_rebase_same_head success noop same success work same --keep-base master
77 test_rebase_same_head success noop same success work same --keep-base
78 test_rebase_same_head success noop same success work same --no-fork-point
79 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
80 test_rebase_same_head success noop same success work same --fork-point master
81 test_rebase_same_head success noop same success work diff --fork-point --onto B B
82 test_rebase_same_head success noop same success work diff --fork-point --onto B... B
83 test_rebase_same_head success noop same success work same --fork-point --onto master... master
84 test_rebase_same_head success noop same success work same --keep-base --keep-base master
86 test_expect_success 'add work same to side' '
87 test_commit E
90 changes='our changes'
91 test_rebase_same_head success noop same success work same
92 test_rebase_same_head success noop same success work same master
93 test_rebase_same_head success noop same success work diff --onto B B
94 test_rebase_same_head success noop same success work diff --onto B... B
95 test_rebase_same_head success noop same success work same --onto master... master
96 test_rebase_same_head success noop same success work same --keep-base master
97 test_rebase_same_head success noop same success work same --keep-base
98 test_rebase_same_head success noop same success work same --no-fork-point
99 test_rebase_same_head success noop same success work same --keep-base --no-fork-point
100 test_rebase_same_head success noop same success work same --fork-point master
101 test_rebase_same_head success noop same success work diff --fork-point --onto B B
102 test_rebase_same_head success noop same success work diff --fork-point --onto B... B
103 test_rebase_same_head success noop same success work same --fork-point --onto master... master
104 test_rebase_same_head success noop same success work same --fork-point --keep-base master
106 test_expect_success 'add work same to upstream' '
107 git checkout master &&
108 test_commit F &&
109 git checkout side
112 changes='our and their changes'
113 test_rebase_same_head success noop same success work diff --onto B B
114 test_rebase_same_head success noop same success work diff --onto B... B
115 test_rebase_same_head success noop same success work diff --onto master... master
116 test_rebase_same_head success noop same success work diff --keep-base master
117 test_rebase_same_head success noop same success work diff --keep-base
118 test_rebase_same_head failure work same success work diff --fork-point --onto B B
119 test_rebase_same_head failure work same success work diff --fork-point --onto B... B
120 test_rebase_same_head success noop same success work diff --fork-point --onto master... master
121 test_rebase_same_head success noop same success work diff --fork-point --keep-base master
123 test_done