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
10 test_expect_success setup
'
14 git commit -m "first" &&
17 git checkout -b other &&
18 echo second >> file1 &&
21 git commit -m "second" &&
24 cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1
25 cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d
29 test_expect_success
'cherry-pick using --ff fast forwards' '
31 git reset --hard first &&
33 git cherry-pick --ff second &&
34 test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)"
37 test_expect_success
'cherry-pick not using --ff does not fast forwards' '
39 git reset --hard first &&
41 git cherry-pick second &&
42 test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)"
46 # We setup the following graph:
52 # (This has been taken from t3502-cherry-pick-merge.sh)
54 test_expect_success
'merge setup' '
56 git reset --hard first &&
60 git commit -m "add line to A" A &&
62 git checkout -b side first &&
66 git commit -m "add line to B" B &&
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 --
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 --
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)"
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)"
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
105 test_expect_success
'cherry pick a root commit with --ff' '
106 git reset --hard first -- &&
110 git commit --amend -m "file2" &&
111 git cherry-pick --ff first &&
112 test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)"
115 test_expect_success
'cherry-pick --ff on unborn branch' '
116 git checkout --orphan unborn &&
117 git rm --cached -r . &&
119 git cherry-pick --ff first &&
120 test_cmp_rev first HEAD