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