revision: fix leaking parents when simplifying commits
[git/gitster.git] / t / t3431-rebase-fork-point.sh
blob0bb284d61dbfae3077c7408ba266ca596e61207d
1 #!/bin/sh
3 # Copyright (c) 2019 Denton Liu
6 test_description='git rebase --fork-point test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
14 # A---B---D---E (main)
15 # \
16 # C*---F---G (side)
18 # C was formerly part of main but main was rewound to remove C
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
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
46 test_rebase () {
47 expected="$1" &&
48 shift &&
49 test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
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
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
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
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
68 test_rebase 'G F C E D B A' refs/heads/main
69 test_rebase 'G F C E D B A' main
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
74 test_rebase 'G F C B A' --keep-base refs/heads/main
75 test_rebase 'G F C B A' --keep-base main
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
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
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"
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"
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
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
111 test_expect_success 'rebase.forkPoint set to true and --root given' '
112 test_config rebase.forkPoint true &&
113 git rebase --root
116 test_done