]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3506-cherry-pick-ff.sh
Merge branch 'pb/ci-matrix-wo-shortcut'
[thirdparty/git.git] / t / t3506-cherry-pick-ff.sh
CommitLineData
b5c1a28b
CC
1#!/bin/sh
2
3test_description='test cherry-picking with --ff option'
4
cbc75a12 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
b5c1a28b
CC
8. ./test-lib.sh
9
10test_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" &&
19ce5496 22 git tag second &&
23 test_oid_cache <<-EOF
24 cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1
25 cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d
26 EOF
b5c1a28b
CC
27'
28
29test_expect_success 'cherry-pick using --ff fast forwards' '
cbc75a12 30 git checkout main &&
b5c1a28b
CC
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
37test_expect_success 'cherry-pick not using --ff does not fast forwards' '
cbc75a12 38 git checkout main &&
b5c1a28b
CC
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#
54test_expect_success 'merge setup' '
cbc75a12 55 git checkout main &&
b5c1a28b
CC
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 &&
cbc75a12 68 git checkout main &&
b5c1a28b
CC
69 git merge side &&
70 git tag C &&
71 git checkout -b new A
72'
73
1c320135 74test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' '
b5c1a28b 75 git reset --hard A -- &&
1c320135
SO
76 git cherry-pick --ff -m 1 B &&
77 git diff --exit-code C --
b5c1a28b
CC
78'
79
80test_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
86test_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
93test_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
100test_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
6355e505
BC
105test_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 &&
19ce5496 112 test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)"
6355e505
BC
113'
114
7a96c386 115test_expect_success 'cherry-pick --ff on unborn branch' '
334ae397
MZ
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
b5c1a28b 123test_done