]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3432-rebase-fast-forward.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/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
334afbc7
JS
8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
793ac7e3
DL
11. ./test-lib.sh
12
13test_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
21test_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
42test_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
88changes='no changes'
4effc5bc 89test_rebase_same_head success noop same success work same
9a70f3d4
EN
90test_rebase_same_head success noop same success work same master
91test_rebase_same_head success noop same success work diff --onto B B
92test_rebase_same_head success noop same success work diff --onto B... B
93test_rebase_same_head success noop same success work same --onto master... master
94test_rebase_same_head success noop same success work same --keep-base master
95test_rebase_same_head success noop same success work same --keep-base
96test_rebase_same_head success noop same success work same --no-fork-point
97test_rebase_same_head success noop same success work same --keep-base --no-fork-point
4effc5bc
DL
98test_rebase_same_head success noop same success work same --fork-point master
99test_rebase_same_head success noop same success work diff --fork-point --onto B B
100test_rebase_same_head success noop same success work diff --fork-point --onto B... B
101test_rebase_same_head success noop same success work same --fork-point --onto master... master
414d924b 102test_rebase_same_head success noop same success work same --keep-base --keep-base master
793ac7e3 103
4336d365 104test_expect_success 'add work same to side' '
793ac7e3
DL
105 test_commit E
106'
107
108changes='our changes'
4effc5bc 109test_rebase_same_head success noop same success work same
9a70f3d4
EN
110test_rebase_same_head success noop same success work same master
111test_rebase_same_head success noop same success work diff --onto B B
112test_rebase_same_head success noop same success work diff --onto B... B
113test_rebase_same_head success noop same success work same --onto master... master
114test_rebase_same_head success noop same success work same --keep-base master
115test_rebase_same_head success noop same success work same --keep-base
116test_rebase_same_head success noop same success work same --no-fork-point
117test_rebase_same_head success noop same success work same --keep-base --no-fork-point
4effc5bc
DL
118test_rebase_same_head success noop same success work same --fork-point master
119test_rebase_same_head success noop same success work diff --fork-point --onto B B
120test_rebase_same_head success noop same success work diff --fork-point --onto B... B
121test_rebase_same_head success noop same success work same --fork-point --onto master... master
414d924b 122test_rebase_same_head success noop same success work same --fork-point --keep-base master
793ac7e3 123
4336d365 124test_expect_success 'add work same to upstream' '
793ac7e3
DL
125 git checkout master &&
126 test_commit F &&
127 git checkout side
128'
129
130changes='our and their changes'
9a70f3d4
EN
131test_rebase_same_head success noop same success work diff --onto B B
132test_rebase_same_head success noop same success work diff --onto B... B
c0efb4c1 133test_rebase_same_head success noop same success work diff --onto master... master
414d924b
DL
134test_rebase_same_head success noop same success work diff --keep-base master
135test_rebase_same_head success noop same success work diff --keep-base
c9efc216
ÆAB
136test_rebase_same_head failure work same success work diff --fork-point --onto B B
137test_rebase_same_head failure work same success work diff --fork-point --onto B... B
c0efb4c1 138test_rebase_same_head success noop same success work diff --fork-point --onto master... master
414d924b 139test_rebase_same_head success noop same success work diff --fork-point --keep-base master
793ac7e3
DL
140
141test_done