Merge branch 'ak/corrected-commit-date'
[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-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         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
32 test_rebase () {
33         expected="$1" &&
34         shift &&
35         test_expect_success "git rebase $*" "
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
47 test_rebase 'G F E D B A'
48 test_rebase 'G F D B A' --onto D
49 test_rebase 'G F B A' --keep-base
50 test_rebase 'G F C E D B A' --no-fork-point
51 test_rebase 'G F C D B A' --no-fork-point --onto D
52 test_rebase 'G F C B A' --no-fork-point --keep-base
53
54 test_rebase 'G F E D B A' --fork-point refs/heads/main
55 test_rebase 'G F E D B A' --fork-point main
56
57 test_rebase 'G F D B A' --fork-point --onto D refs/heads/main
58 test_rebase 'G F D B A' --fork-point --onto D main
59
60 test_rebase 'G F B A' --fork-point --keep-base refs/heads/main
61 test_rebase 'G F B A' --fork-point --keep-base main
62
63 test_rebase 'G F C E D B A' refs/heads/main
64 test_rebase 'G F C E D B A' main
65
66 test_rebase 'G F C D B A' --onto D refs/heads/main
67 test_rebase 'G F C D B A' --onto D main
68
69 test_rebase 'G F C B A' --keep-base refs/heads/main
70 test_rebase 'G F C B A' --keep-base main
71
72 test_expect_success 'git rebase --fork-point with ambigous refname' '
73         git checkout main &&
74         git checkout -b one &&
75         git checkout side &&
76         git tag one &&
77         test_must_fail git rebase --fork-point --onto D one
78 '
79
80 test_done