3 test_description
='test cherry-picking with --ff option'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
15 git commit -m "first" &&
18 git checkout -b other &&
19 echo second >> file1 &&
22 git commit -m "second" &&
25 cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1
26 cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d
30 test_expect_success
'cherry-pick using --ff fast forwards' '
32 git reset --hard first &&
34 git cherry-pick --ff second &&
35 test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)"
38 test_expect_success
'cherry-pick not using --ff does not fast forwards' '
40 git reset --hard first &&
42 git cherry-pick second &&
43 test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)"
47 # We setup the following graph:
53 # (This has been taken from t3502-cherry-pick-merge.sh)
55 test_expect_success
'merge setup' '
57 git reset --hard first &&
61 git commit -m "add line to A" A &&
63 git checkout -b side first &&
67 git commit -m "add line to B" B &&
75 test_expect_success
'cherry-pick explicit first parent of a non-merge with --ff' '
76 git reset --hard A -- &&
77 git cherry-pick --ff -m 1 B &&
78 git diff --exit-code C --
81 test_expect_success
'cherry pick a merge with --ff but without -m should fail' '
82 git reset --hard A -- &&
83 test_must_fail git cherry-pick --ff C &&
84 git diff --exit-code A --
87 test_expect_success
'cherry pick with --ff a merge (1)' '
88 git reset --hard A -- &&
89 git cherry-pick --ff -m 1 C &&
90 git diff --exit-code C &&
91 test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
94 test_expect_success
'cherry pick with --ff a merge (2)' '
95 git reset --hard B -- &&
96 git cherry-pick --ff -m 2 C &&
97 git diff --exit-code C &&
98 test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
101 test_expect_success
'cherry pick a merge relative to nonexistent parent with --ff should fail' '
102 git reset --hard B -- &&
103 test_must_fail git cherry-pick --ff -m 3 C
106 test_expect_success
'cherry pick a root commit with --ff' '
107 git reset --hard first -- &&
111 git commit --amend -m "file2" &&
112 git cherry-pick --ff first &&
113 test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)"
116 test_expect_success
'cherry-pick --ff on unborn branch' '
117 git checkout --orphan unborn &&
118 git rm --cached -r . &&
120 git cherry-pick --ff first &&
121 test_cmp_rev first HEAD