blob: 1d0b15380edf3195b10e25a7d8d36f93330b95f5 [file] [log] [blame]
Denton Liu359eceb2019-08-25 05:11:57 -04001#!/bin/sh
2#
3# Copyright (c) 2019 Denton Liu
4#
5
6test_description='git rebase --fork-point test'
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 Liu359eceb2019-08-25 05:11:57 -040011. ./test-lib.sh
12
Johannes Schindelind1c02d92020-11-18 23:44:25 +000013# A---B---D---E (main)
Denton Liu359eceb2019-08-25 05:11:57 -040014# \
15# C*---F---G (side)
16#
Johannes Schindelind1c02d92020-11-18 23:44:25 +000017# C was formerly part of main but main was rewound to remove C
Denton Liu359eceb2019-08-25 05:11:57 -040018#
19test_expect_success setup '
20 test_commit A &&
21 test_commit B &&
22 test_commit C &&
23 git branch -t side &&
24 git reset --hard HEAD^ &&
25 test_commit D &&
26 test_commit E &&
27 git checkout side &&
28 test_commit F &&
29 test_commit G
30'
31
Alex Henrie2803d802021-02-23 00:18:40 -070032do_test_rebase () {
33 expected="$1" &&
34 shift &&
Junio C Hamano682bbad2021-02-25 16:43:31 -080035 git checkout main &&
Alex Henrie2803d802021-02-23 00:18:40 -070036 git reset --hard E &&
37 git checkout side &&
38 git reset --hard G &&
39 git rebase $* &&
40 test_write_lines $expected >expect &&
41 git log --pretty=%s >actual &&
42 test_cmp expect actual
43}
44
Denton Liu359eceb2019-08-25 05:11:57 -040045test_rebase () {
46 expected="$1" &&
47 shift &&
Alex Henrie2803d802021-02-23 00:18:40 -070048 test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
Denton Liu359eceb2019-08-25 05:11:57 -040049}
50
51test_rebase 'G F E D B A'
52test_rebase 'G F D B A' --onto D
Denton Liu414d9242019-08-27 01:38:06 -040053test_rebase 'G F B A' --keep-base
Denton Liu359eceb2019-08-25 05:11:57 -040054test_rebase 'G F C E D B A' --no-fork-point
55test_rebase 'G F C D B A' --no-fork-point --onto D
Denton Liu414d9242019-08-27 01:38:06 -040056test_rebase 'G F C B A' --no-fork-point --keep-base
Junio C Hamanof08132f2019-12-09 10:51:47 -080057
Johannes Schindelind1c02d92020-11-18 23:44:25 +000058test_rebase 'G F E D B A' --fork-point refs/heads/main
59test_rebase 'G F E D B A' --fork-point main
Junio C Hamanof08132f2019-12-09 10:51:47 -080060
Johannes Schindelind1c02d92020-11-18 23:44:25 +000061test_rebase 'G F D B A' --fork-point --onto D refs/heads/main
62test_rebase 'G F D B A' --fork-point --onto D main
Junio C Hamanof08132f2019-12-09 10:51:47 -080063
Johannes Schindelind1c02d92020-11-18 23:44:25 +000064test_rebase 'G F B A' --fork-point --keep-base refs/heads/main
65test_rebase 'G F B A' --fork-point --keep-base main
Junio C Hamanof08132f2019-12-09 10:51:47 -080066
Johannes Schindelind1c02d92020-11-18 23:44:25 +000067test_rebase 'G F C E D B A' refs/heads/main
68test_rebase 'G F C E D B A' main
Junio C Hamanof08132f2019-12-09 10:51:47 -080069
Johannes Schindelind1c02d92020-11-18 23:44:25 +000070test_rebase 'G F C D B A' --onto D refs/heads/main
71test_rebase 'G F C D B A' --onto D main
Junio C Hamanof08132f2019-12-09 10:51:47 -080072
Johannes Schindelind1c02d92020-11-18 23:44:25 +000073test_rebase 'G F C B A' --keep-base refs/heads/main
74test_rebase 'G F C B A' --keep-base main
Junio C Hamanof08132f2019-12-09 10:51:47 -080075
76test_expect_success 'git rebase --fork-point with ambigous refname' '
Johannes Schindelind1c02d92020-11-18 23:44:25 +000077 git checkout main &&
Junio C Hamanof08132f2019-12-09 10:51:47 -080078 git checkout -b one &&
79 git checkout side &&
80 git tag one &&
81 test_must_fail git rebase --fork-point --onto D one
82'
Denton Liu359eceb2019-08-25 05:11:57 -040083
Alex Henrie2803d802021-02-23 00:18:40 -070084test_expect_success '--fork-point and --root both given' '
85 test_must_fail git rebase --fork-point --root 2>err &&
Jean-Noël Avila12909b62022-01-05 20:02:16 +000086 test_i18ngrep "cannot be used together" err
Alex Henrie2803d802021-02-23 00:18:40 -070087'
88
89test_expect_success 'rebase.forkPoint set to false' '
90 test_config rebase.forkPoint false &&
91 do_test_rebase "G F C E D B A"
92'
93
94test_expect_success 'rebase.forkPoint set to false and then to true' '
95 test_config_global rebase.forkPoint false &&
96 test_config rebase.forkPoint true &&
97 do_test_rebase "G F E D B A"
98'
99
100test_expect_success 'rebase.forkPoint set to false and command line says --fork-point' '
101 test_config rebase.forkPoint false &&
102 do_test_rebase "G F E D B A" --fork-point
103'
104
105test_expect_success 'rebase.forkPoint set to true and command line says --no-fork-point' '
106 test_config rebase.forkPoint true &&
107 do_test_rebase "G F C E D B A" --no-fork-point
108'
109
110test_expect_success 'rebase.forkPoint set to true and --root given' '
111 test_config rebase.forkPoint true &&
112 git rebase --root
113'
114
Denton Liu359eceb2019-08-25 05:11:57 -0400115test_done