Merge branch 'bc/more-git-var'
[alt-git.git] / t / t3506-cherry-pick-ff.sh
blobb71bad17b853c566caac5828c19453da9c862647
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
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 &&
18 git checkout -b other &&
19 echo second >> file1 &&
20 git add file1 &&
21 test_tick &&
22 git commit -m "second" &&
23 git tag second &&
24 test_oid_cache <<-EOF
25 cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1
26 cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d
27 EOF
30 test_expect_success 'cherry-pick using --ff fast forwards' '
31 git checkout main &&
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)"
38 test_expect_success 'cherry-pick not using --ff does not fast forwards' '
39 git checkout main &&
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)"
47 # We setup the following graph:
49 # B---C
50 # / /
51 # first---A
53 # (This has been taken from t3502-cherry-pick-merge.sh)
55 test_expect_success 'merge setup' '
56 git checkout main &&
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 &&
69 git checkout main &&
70 git merge side &&
71 git tag C &&
72 git checkout -b new A
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 -- &&
108 git rm file1 &&
109 echo first >file2 &&
110 git add file2 &&
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 . &&
119 rm -rf * &&
120 git cherry-pick --ff first &&
121 test_cmp_rev first HEAD
124 test_done