]>
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 | ||
359ecebc DL |
11 | . ./test-lib.sh |
12 | ||
d1c02d93 | 13 | # A---B---D---E (main) |
359ecebc DL |
14 | # \ |
15 | # C*---F---G (side) | |
16 | # | |
d1c02d93 | 17 | # C was formerly part of main but main was rewound to remove C |
359ecebc DL |
18 | # |
19 | test_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 | ||
2803d800 AH |
32 | do_test_rebase () { |
33 | expected="$1" && | |
34 | shift && | |
682bbad6 | 35 | git checkout main && |
2803d800 AH |
36 | 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 | ||
359ecebc DL |
45 | test_rebase () { |
46 | expected="$1" && | |
47 | shift && | |
2803d800 | 48 | test_expect_success "git rebase $*" "do_test_rebase '$expected' $*" |
359ecebc DL |
49 | } |
50 | ||
51 | test_rebase 'G F E D B A' | |
52 | test_rebase 'G F D B A' --onto D | |
414d924b | 53 | test_rebase 'G F B A' --keep-base |
359ecebc DL |
54 | test_rebase 'G F C E D B A' --no-fork-point |
55 | test_rebase 'G F C D B A' --no-fork-point --onto D | |
414d924b | 56 | test_rebase 'G F C B A' --no-fork-point --keep-base |
f08132f8 | 57 | |
d1c02d93 JS |
58 | test_rebase 'G F E D B A' --fork-point refs/heads/main |
59 | test_rebase 'G F E D B A' --fork-point main | |
f08132f8 | 60 | |
d1c02d93 JS |
61 | test_rebase 'G F D B A' --fork-point --onto D refs/heads/main |
62 | test_rebase 'G F D B A' --fork-point --onto D main | |
f08132f8 | 63 | |
d1c02d93 JS |
64 | test_rebase 'G F B A' --fork-point --keep-base refs/heads/main |
65 | test_rebase 'G F B A' --fork-point --keep-base main | |
f08132f8 | 66 | |
d1c02d93 JS |
67 | test_rebase 'G F C E D B A' refs/heads/main |
68 | test_rebase 'G F C E D B A' main | |
f08132f8 | 69 | |
d1c02d93 JS |
70 | test_rebase 'G F C D B A' --onto D refs/heads/main |
71 | test_rebase 'G F C D B A' --onto D main | |
f08132f8 | 72 | |
d1c02d93 JS |
73 | test_rebase 'G F C B A' --keep-base refs/heads/main |
74 | test_rebase 'G F C B A' --keep-base main | |
f08132f8 JH |
75 | |
76 | test_expect_success 'git rebase --fork-point with ambigous refname' ' | |
d1c02d93 | 77 | git checkout main && |
f08132f8 JH |
78 | git checkout -b one && |
79 | git checkout side && | |
80 | git tag one && | |
81 | test_must_fail git rebase --fork-point --onto D one | |
82 | ' | |
359ecebc | 83 | |
2803d800 AH |
84 | test_expect_success '--fork-point and --root both given' ' |
85 | test_must_fail git rebase --fork-point --root 2>err && | |
86 | test_i18ngrep "cannot combine" err | |
87 | ' | |
88 | ||
89 | test_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 | ||
94 | test_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 | ||
100 | test_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 | ||
105 | test_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 | ||
110 | test_expect_success 'rebase.forkPoint set to true and --root given' ' | |
111 | test_config rebase.forkPoint true && | |
112 | git rebase --root | |
113 | ' | |
114 | ||
359ecebc | 115 | test_done |