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