The second batch
[git] / t / t3506-cherry-pick-ff.sh
1 #!/bin/sh
2
3 test_description='test cherry-picking with --ff option'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success setup '
11         echo first > file1 &&
12         git add file1 &&
13         test_tick &&
14         git commit -m "first" &&
15         git tag first &&
16
17         git checkout -b other &&
18         echo second >> file1 &&
19         git add file1 &&
20         test_tick &&
21         git commit -m "second" &&
22         git tag second &&
23         test_oid_cache <<-EOF
24         cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1
25         cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d
26         EOF
27 '
28
29 test_expect_success 'cherry-pick using --ff fast forwards' '
30         git checkout main &&
31         git reset --hard first &&
32         test_tick &&
33         git cherry-pick --ff second &&
34         test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)"
35 '
36
37 test_expect_success 'cherry-pick not using --ff does not fast forwards' '
38         git checkout main &&
39         git reset --hard first &&
40         test_tick &&
41         git cherry-pick second &&
42         test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)"
43 '
44
45 #
46 # We setup the following graph:
47 #
48 #             B---C
49 #            /   /
50 #       first---A
51 #
52 # (This has been taken from t3502-cherry-pick-merge.sh)
53 #
54 test_expect_success 'merge setup' '
55         git checkout main &&
56         git reset --hard first &&
57         echo new line >A &&
58         git add A &&
59         test_tick &&
60         git commit -m "add line to A" A &&
61         git tag A &&
62         git checkout -b side first &&
63         echo new line >B &&
64         git add B &&
65         test_tick &&
66         git commit -m "add line to B" B &&
67         git tag B &&
68         git checkout main &&
69         git merge side &&
70         git tag C &&
71         git checkout -b new A
72 '
73
74 test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' '
75         git reset --hard A -- &&
76         git cherry-pick --ff -m 1 B &&
77         git diff --exit-code C --
78 '
79
80 test_expect_success 'cherry pick a merge with --ff but without -m should fail' '
81         git reset --hard A -- &&
82         test_must_fail git cherry-pick --ff C &&
83         git diff --exit-code A --
84 '
85
86 test_expect_success 'cherry pick with --ff a merge (1)' '
87         git reset --hard A -- &&
88         git cherry-pick --ff -m 1 C &&
89         git diff --exit-code C &&
90         test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
91 '
92
93 test_expect_success 'cherry pick with --ff a merge (2)' '
94         git reset --hard B -- &&
95         git cherry-pick --ff -m 2 C &&
96         git diff --exit-code C &&
97         test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
98 '
99
100 test_expect_success 'cherry pick a merge relative to nonexistent parent with --ff should fail' '
101         git reset --hard B -- &&
102         test_must_fail git cherry-pick --ff -m 3 C
103 '
104
105 test_expect_success 'cherry pick a root commit with --ff' '
106         git reset --hard first -- &&
107         git rm file1 &&
108         echo first >file2 &&
109         git add file2 &&
110         git commit --amend -m "file2" &&
111         git cherry-pick --ff first &&
112         test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)"
113 '
114
115 test_expect_success 'cherry-pick --ff on unborn branch' '
116         git checkout --orphan unborn &&
117         git rm --cached -r . &&
118         rm -rf * &&
119         git cherry-pick --ff first &&
120         test_cmp_rev first HEAD
121 '
122
123 test_done