]>
Commit | Line | Data |
---|---|---|
b5c1a28b CC |
1 | #!/bin/sh |
2 | ||
3 | test_description='test cherry-picking with --ff option' | |
4 | ||
cbc75a12 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
9ff2f060 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
b5c1a28b CC |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success setup ' | |
12 | echo first > file1 && | |
13 | git add file1 && | |
14 | test_tick && | |
15 | git commit -m "first" && | |
16 | git tag first && | |
17 | ||
18 | git checkout -b other && | |
19 | echo second >> file1 && | |
20 | git add file1 && | |
21 | test_tick && | |
22 | git commit -m "second" && | |
19ce5496 | 23 | git tag second && |
24 | test_oid_cache <<-EOF | |
25 | cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1 | |
26 | cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d | |
27 | EOF | |
b5c1a28b CC |
28 | ' |
29 | ||
30 | test_expect_success 'cherry-pick using --ff fast forwards' ' | |
cbc75a12 | 31 | git checkout main && |
b5c1a28b CC |
32 | git reset --hard first && |
33 | test_tick && | |
34 | git cherry-pick --ff second && | |
35 | test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)" | |
36 | ' | |
37 | ||
38 | test_expect_success 'cherry-pick not using --ff does not fast forwards' ' | |
cbc75a12 | 39 | git checkout main && |
b5c1a28b CC |
40 | git reset --hard first && |
41 | test_tick && | |
42 | git cherry-pick second && | |
43 | test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)" | |
44 | ' | |
45 | ||
46 | # | |
47 | # We setup the following graph: | |
48 | # | |
49 | # B---C | |
50 | # / / | |
51 | # first---A | |
52 | # | |
53 | # (This has been taken from t3502-cherry-pick-merge.sh) | |
54 | # | |
55 | test_expect_success 'merge setup' ' | |
cbc75a12 | 56 | git checkout main && |
b5c1a28b CC |
57 | git reset --hard first && |
58 | echo new line >A && | |
59 | git add A && | |
60 | test_tick && | |
61 | git commit -m "add line to A" A && | |
62 | git tag A && | |
63 | git checkout -b side first && | |
64 | echo new line >B && | |
65 | git add B && | |
66 | test_tick && | |
67 | git commit -m "add line to B" B && | |
68 | git tag B && | |
cbc75a12 | 69 | git checkout main && |
b5c1a28b CC |
70 | git merge side && |
71 | git tag C && | |
72 | git checkout -b new A | |
73 | ' | |
74 | ||
1c320135 | 75 | test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' ' |
b5c1a28b | 76 | git reset --hard A -- && |
1c320135 SO |
77 | git cherry-pick --ff -m 1 B && |
78 | git diff --exit-code C -- | |
b5c1a28b CC |
79 | ' |
80 | ||
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 -- | |
85 | ' | |
86 | ||
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)" | |
92 | ' | |
93 | ||
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)" | |
99 | ' | |
100 | ||
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 | |
104 | ' | |
105 | ||
6355e505 BC |
106 | test_expect_success 'cherry pick a root commit with --ff' ' |
107 | git reset --hard first -- && | |
108 | git rm file1 && | |
109 | echo first >file2 && | |
110 | git add file2 && | |
111 | git commit --amend -m "file2" && | |
112 | git cherry-pick --ff first && | |
19ce5496 | 113 | test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)" |
6355e505 BC |
114 | ' |
115 | ||
7a96c386 | 116 | test_expect_success 'cherry-pick --ff on unborn branch' ' |
334ae397 MZ |
117 | git checkout --orphan unborn && |
118 | git rm --cached -r . && | |
119 | rm -rf * && | |
120 | git cherry-pick --ff first && | |
121 | test_cmp_rev first HEAD | |
122 | ' | |
123 | ||
b5c1a28b | 124 | test_done |