Raw
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-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 #
19 test_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
38 do_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
51 test_rebase () {
52 expected="$1" &&
53 shift &&
54 test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
55 }
56
57 test_rebase 'G F E D B A'
58 test_rebase 'G F D B A' --onto D
59 test_rebase 'G F C B A' --keep-base
60 test_rebase 'G F C E D B A' --no-fork-point
61 test_rebase 'G F C D B A' --no-fork-point --onto D
62 test_rebase 'G F C B A' --no-fork-point --keep-base
63
64 test_rebase 'G F E D B A' --fork-point refs/heads/main
65 test_rebase 'G F E D B A' --fork-point main
66
67 test_rebase 'G F D B A' --fork-point --onto D refs/heads/main
68 test_rebase 'G F D B A' --fork-point --onto D main
69
70 test_rebase 'G F B A' --fork-point --keep-base refs/heads/main
71 test_rebase 'G F B A' --fork-point --keep-base main
72
73 test_rebase 'G F C E D B A' refs/heads/main
74 test_rebase 'G F C E D B A' main
75
76 test_rebase 'G F C D B A' --onto D refs/heads/main
77 test_rebase 'G F C D B A' --onto D main
78
79 test_rebase 'G F C B A' --keep-base refs/heads/main
80 test_rebase 'G F C B A' --keep-base main
81
82 test_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
90 test_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
95 test_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
100 test_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
106 test_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
111 test_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
116 test_expect_success 'rebase.forkPoint set to true and --root given' '
117 test_config rebase.forkPoint true &&
118 git rebase --root
119 '
120
121 test_done