]>
Commit | Line | Data |
---|---|---|
359ecebc DL |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2019 Denton Liu | |
4 | # | |
5 | ||
6 | test_description='git rebase --fork-point test' | |
7 | ||
d1c02d93 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
0c10ed19 | 11 | TEST_PASSES_SANITIZE_LEAK=true |
359ecebc DL |
12 | . ./test-lib.sh |
13 | ||
d1c02d93 | 14 | # A---B---D---E (main) |
359ecebc DL |
15 | # \ |
16 | # C*---F---G (side) | |
17 | # | |
d1c02d93 | 18 | # C was formerly part of main but main was rewound to remove C |
359ecebc DL |
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 | ||
2803d800 AH |
33 | do_test_rebase () { |
34 | expected="$1" && | |
35 | shift && | |
682bbad6 | 36 | git checkout main && |
2803d800 AH |
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 | ||
359ecebc DL |
46 | test_rebase () { |
47 | expected="$1" && | |
48 | shift && | |
2803d800 | 49 | test_expect_success "git rebase $*" "do_test_rebase '$expected' $*" |
359ecebc DL |
50 | } |
51 | ||
52 | test_rebase 'G F E D B A' | |
53 | test_rebase 'G F D B A' --onto D | |
aa1df814 | 54 | test_rebase 'G F C B A' --keep-base |
359ecebc DL |
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 | |
414d924b | 57 | test_rebase 'G F C B A' --no-fork-point --keep-base |
f08132f8 | 58 | |
d1c02d93 JS |
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 | |
f08132f8 | 61 | |
d1c02d93 JS |
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 | |
f08132f8 | 64 | |
d1c02d93 JS |
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 | |
f08132f8 | 67 | |
d1c02d93 JS |
68 | test_rebase 'G F C E D B A' refs/heads/main |
69 | test_rebase 'G F C E D B A' main | |
f08132f8 | 70 | |
d1c02d93 JS |
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 | |
f08132f8 | 73 | |
d1c02d93 JS |
74 | test_rebase 'G F C B A' --keep-base refs/heads/main |
75 | test_rebase 'G F C B A' --keep-base main | |
f08132f8 JH |
76 | |
77 | test_expect_success 'git rebase --fork-point with ambigous refname' ' | |
d1c02d93 | 78 | git checkout main && |
f08132f8 JH |
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 | ' | |
359ecebc | 84 | |
2803d800 AH |
85 | test_expect_success '--fork-point and --root both given' ' |
86 | test_must_fail git rebase --fork-point --root 2>err && | |
6789275d | 87 | test_grep "cannot be used together" err |
2803d800 AH |
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 | ||
359ecebc | 116 | test_done |