clone_submodule: avoid using `access()` on directories
[git.git] / t / t3432-rebase-fast-forward.sh
blob5086e14c02207184bd7c048ee2bc2419ad4d1b34
1 #!/bin/sh
3 # Copyright (c) 2019 Denton Liu
6 test_description='ensure rebase fast-forwards commits when possible'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
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
21 test_rebase_same_head () {
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 &&
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" "$*"
42 test_rebase_same_head_ () {
43 status="$1" &&
44 shift &&
45 what="$1" &&
46 shift &&
47 cmp="$1" &&
48 shift &&
49 abbreviate="$1" &&
50 shift &&
51 flag="$1"
52 shift &&
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 &&
64 oldhead=\$(git rev-parse HEAD) &&
65 test_when_finished 'git reset --hard \$oldhead' &&
66 git reflog HEAD >expect &&
67 git rebase$flag $* >stdout &&
68 git reflog HEAD >actual &&
69 if test $what = work
70 then
71 old=\$(wc -l <expect) &&
72 test_line_count '-gt' \$old actual
73 elif test $what = noop
74 then
75 test_cmp expect actual
76 fi &&
77 newhead=\$(git rev-parse HEAD) &&
78 if test $cmp = same
79 then
80 test_cmp_rev \$oldhead \$newhead
81 elif test $cmp = diff
82 then
83 test_cmp_rev ! \$oldhead \$newhead
88 changes='no changes'
89 test_rebase_same_head success noop same success work same
90 test_rebase_same_head success noop same success work same main
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 main... main
94 test_rebase_same_head success noop same success work same --keep-base main
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
98 test_rebase_same_head success noop same success work same --fork-point main
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 main... main
102 test_rebase_same_head success noop same success work same --keep-base --keep-base main
104 test_expect_success 'add work same to side' '
105 test_commit E
108 changes='our changes'
109 test_rebase_same_head success noop same success work same
110 test_rebase_same_head success noop same success work same main
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 main... main
114 test_rebase_same_head success noop same success work same --keep-base main
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
118 test_rebase_same_head success noop same success work same --fork-point main
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 main... main
122 test_rebase_same_head success noop same success work same --fork-point --keep-base main
124 test_expect_success 'add work same to upstream' '
125 git checkout main &&
126 test_commit F &&
127 git checkout side
130 changes='our and their changes'
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
133 test_rebase_same_head success noop same success work diff --onto main... main
134 test_rebase_same_head success noop same success work diff --keep-base main
135 test_rebase_same_head success noop same success work diff --keep-base
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
138 test_rebase_same_head success noop same success work diff --fork-point --onto main... main
139 test_rebase_same_head success noop same success work diff --fork-point --keep-base main
141 test_done