blob: 5086e14c02207184bd7c048ee2bc2419ad4d1b34 [file] [log] [blame]
Denton Liu793ac7e2019-08-25 05:12:00 -04001#!/bin/sh
2#
3# Copyright (c) 2019 Denton Liu
4#
5
6test_description='ensure rebase fast-forwards commits when possible'
7
Johannes Schindelind1c02d92020-11-18 23:44:25 +00008GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00009export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
Denton Liu793ac7e2019-08-25 05:12:00 -040011. ./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 () {
Ævar Arnfjörð Bjarmasonc9efc212019-08-27 01:37:53 -040022 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 &&
Alban Gruinde9f1d32020-03-30 14:42:36 +020034 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" "$*"
Ævar Arnfjörð Bjarmasonc9efc212019-08-27 01:37:53 -040040}
41
42test_rebase_same_head_ () {
Denton Liu793ac7e2019-08-25 05:12:00 -040043 status="$1" &&
44 shift &&
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040045 what="$1" &&
46 shift &&
47 cmp="$1" &&
48 shift &&
Alban Gruinde9f1d32020-03-30 14:42:36 +020049 abbreviate="$1" &&
50 shift &&
Ævar Arnfjörð Bjarmasonc9efc212019-08-27 01:37:53 -040051 flag="$1"
52 shift &&
Alban Gruinde9f1d32020-03-30 14:42:36 +020053 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 &&
Denton Liu793ac7e2019-08-25 05:12:00 -040064 oldhead=\$(git rev-parse HEAD) &&
65 test_when_finished 'git reset --hard \$oldhead' &&
Han-Wen Nienhuysce57d852020-07-10 17:19:51 +000066 git reflog HEAD >expect &&
Ævar Arnfjörð Bjarmasonc9efc212019-08-27 01:37:53 -040067 git rebase$flag $* >stdout &&
Han-Wen Nienhuysce57d852020-07-10 17:19:51 +000068 git reflog HEAD >actual &&
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040069 if test $what = work
70 then
Elijah Newren9a70f3d2020-02-15 21:36:30 +000071 old=\$(wc -l <expect) &&
Han-Wen Nienhuysce57d852020-07-10 17:19:51 +000072 test_line_count '-gt' \$old actual
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040073 elif test $what = noop
74 then
Han-Wen Nienhuysce57d852020-07-10 17:19:51 +000075 test_cmp expect actual
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040076 fi &&
Denton Liu793ac7e2019-08-25 05:12:00 -040077 newhead=\$(git rev-parse HEAD) &&
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040078 if test $cmp = same
79 then
80 test_cmp_rev \$oldhead \$newhead
81 elif test $cmp = diff
82 then
Denton Liu2c9e1252019-11-12 15:07:45 -080083 test_cmp_rev ! \$oldhead \$newhead
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -040084 fi
Denton Liu793ac7e2019-08-25 05:12:00 -040085 "
86}
87
88changes='no changes'
Denton Liu4effc5b2019-08-27 01:38:01 -040089test_rebase_same_head success noop same success work same
Johannes Schindelind1c02d92020-11-18 23:44:25 +000090test_rebase_same_head success noop same success work same main
Elijah Newren9a70f3d2020-02-15 21:36:30 +000091test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +000093test_rebase_same_head success noop same success work same --onto main... main
94test_rebase_same_head success noop same success work same --keep-base main
Elijah Newren9a70f3d2020-02-15 21:36:30 +000095test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +000098test_rebase_same_head success noop same success work same --fork-point main
Denton Liu4effc5b2019-08-27 01:38:01 -040099test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000101test_rebase_same_head success noop same success work same --fork-point --onto main... main
102test_rebase_same_head success noop same success work same --keep-base --keep-base main
Denton Liu793ac7e2019-08-25 05:12:00 -0400103
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -0400104test_expect_success 'add work same to side' '
Denton Liu793ac7e2019-08-25 05:12:00 -0400105 test_commit E
106'
107
108changes='our changes'
Denton Liu4effc5b2019-08-27 01:38:01 -0400109test_rebase_same_head success noop same success work same
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000110test_rebase_same_head success noop same success work same main
Elijah Newren9a70f3d2020-02-15 21:36:30 +0000111test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000113test_rebase_same_head success noop same success work same --onto main... main
114test_rebase_same_head success noop same success work same --keep-base main
Elijah Newren9a70f3d2020-02-15 21:36:30 +0000115test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000118test_rebase_same_head success noop same success work same --fork-point main
Denton Liu4effc5b2019-08-27 01:38:01 -0400119test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000121test_rebase_same_head success noop same success work same --fork-point --onto main... main
122test_rebase_same_head success noop same success work same --fork-point --keep-base main
Denton Liu793ac7e2019-08-25 05:12:00 -0400123
Ævar Arnfjörð Bjarmason4336d362019-08-25 05:12:02 -0400124test_expect_success 'add work same to upstream' '
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000125 git checkout main &&
Denton Liu793ac7e2019-08-25 05:12:00 -0400126 test_commit F &&
127 git checkout side
128'
129
130changes='our and their changes'
Elijah Newren9a70f3d2020-02-15 21:36:30 +0000131test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000133test_rebase_same_head success noop same success work diff --onto main... main
134test_rebase_same_head success noop same success work diff --keep-base main
Denton Liu414d9242019-08-27 01:38:06 -0400135test_rebase_same_head success noop same success work diff --keep-base
Ævar Arnfjörð Bjarmasonc9efc212019-08-27 01:37:53 -0400136test_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
Johannes Schindelind1c02d92020-11-18 23:44:25 +0000138test_rebase_same_head success noop same success work diff --fork-point --onto main... main
139test_rebase_same_head success noop same success work diff --fork-point --keep-base main
Denton Liu793ac7e2019-08-25 05:12:00 -0400140
141test_done