rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t3506-cherry-pick-ff.sh
blob7e11bd4a4c5c41c9e326244f598bdc9bb4e4e3ba
1 #!/bin/sh
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-lib.sh
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 &&
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
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)"
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)"
46 # We setup the following graph:
48 # B---C
49 # / /
50 # first---A
52 # (This has been taken from t3502-cherry-pick-merge.sh)
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
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 -- &&
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)"
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
123 test_done