interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t3431-rebase-fork-point.sh

121 lines · 3203 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2019 Denton Liu
4#
5
6test_description='git rebase --fork-point test'
7
8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11. ./test-lib.sh
12
13# A---B---D---E (main)
14# \
15# C*---F---G (side)
16#
17# C was formerly part of main but main was rewound to remove C
18#
19test_expect_success setup '
20 # Commit dates are hardcoded to 2005, and the reflog entries will have
21 # a matching timestamp. Maintenance may thus immediately expire
22 # reflogs if it was running.
23 git config set gc.reflogExpire never &&
24 git config set gc.reflogExpireUnreachable never &&
25
26 test_commit A &&
27 test_commit B &&
28 test_commit C &&
29 git branch -t side &&
30 git reset --hard HEAD^ &&
31 test_commit D &&
32 test_commit E &&
33 git checkout side &&
34 test_commit F &&
35 test_commit G
36'
37
38do_test_rebase () {
39 expected="$1" &&
40 shift &&
41 git checkout main &&
42 git reset --hard E &&
43 git checkout side &&
44 git reset --hard G &&
45 git rebase $* &&
46 test_write_lines $expected >expect &&
47 git log --pretty=%s >actual &&
48 test_cmp expect actual
49}
50
51test_rebase () {
52 expected="$1" &&
53 shift &&
54 test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
55}
56
57test_rebase 'G F E D B A'
58test_rebase 'G F D B A' --onto D
59test_rebase 'G F C B A' --keep-base
60test_rebase 'G F C E D B A' --no-fork-point
61test_rebase 'G F C D B A' --no-fork-point --onto D
62test_rebase 'G F C B A' --no-fork-point --keep-base
63
64test_rebase 'G F E D B A' --fork-point refs/heads/main
65test_rebase 'G F E D B A' --fork-point main
66
67test_rebase 'G F D B A' --fork-point --onto D refs/heads/main
68test_rebase 'G F D B A' --fork-point --onto D main
69
70test_rebase 'G F B A' --fork-point --keep-base refs/heads/main
71test_rebase 'G F B A' --fork-point --keep-base main
72
73test_rebase 'G F C E D B A' refs/heads/main
74test_rebase 'G F C E D B A' main
75
76test_rebase 'G F C D B A' --onto D refs/heads/main
77test_rebase 'G F C D B A' --onto D main
78
79test_rebase 'G F C B A' --keep-base refs/heads/main
80test_rebase 'G F C B A' --keep-base main
81
82test_expect_success 'git rebase --fork-point with ambiguous refname' '
83 git checkout main &&
84 git checkout -b one &&
85 git checkout side &&
86 git tag one &&
87 test_must_fail git rebase --fork-point --onto D one
88'
89
90test_expect_success '--fork-point and --root both given' '
91 test_must_fail git rebase --fork-point --root 2>err &&
92 test_grep "cannot be used together" err
93'
94
95test_expect_success 'rebase.forkPoint set to false' '
96 test_config rebase.forkPoint false &&
97 do_test_rebase "G F C E D B A"
98'
99
100test_expect_success 'rebase.forkPoint set to false and then to true' '
101 test_config_global rebase.forkPoint false &&
102 test_config rebase.forkPoint true &&
103 do_test_rebase "G F E D B A"
104'
105
106test_expect_success 'rebase.forkPoint set to false and command line says --fork-point' '
107 test_config rebase.forkPoint false &&
108 do_test_rebase "G F E D B A" --fork-point
109'
110
111test_expect_success 'rebase.forkPoint set to true and command line says --no-fork-point' '
112 test_config rebase.forkPoint true &&
113 do_test_rebase "G F C E D B A" --no-fork-point
114'
115
116test_expect_success 'rebase.forkPoint set to true and --root given' '
117 test_config rebase.forkPoint true &&
118 git rebase --root
119'
120
121test_done