Christian Couder | b5c1a28 | 2010-03-06 21:34:43 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test cherry-picking with --ff option' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success setup ' |
| 8 | echo first > file1 && |
| 9 | git add file1 && |
| 10 | test_tick && |
| 11 | git commit -m "first" && |
| 12 | git tag first && |
| 13 | |
| 14 | git checkout -b other && |
| 15 | echo second >> file1 && |
| 16 | git add file1 && |
| 17 | test_tick && |
| 18 | git commit -m "second" && |
brian m. carlson | 19ce549 | 2019-08-18 19:16:40 +0000 | [diff] [blame] | 19 | git tag second && |
| 20 | test_oid_cache <<-EOF |
| 21 | cp_ff sha1:1df192cd8bc58a2b275d842cede4d221ad9000d1 |
| 22 | cp_ff sha256:e70d6b7fc064bddb516b8d512c9057094b96ce6ff08e12080acc4fe7f1d60a1d |
| 23 | EOF |
Christian Couder | b5c1a28 | 2010-03-06 21:34:43 +0100 | [diff] [blame] | 24 | ' |
| 25 | |
| 26 | test_expect_success 'cherry-pick using --ff fast forwards' ' |
| 27 | git checkout master && |
| 28 | git reset --hard first && |
| 29 | test_tick && |
| 30 | git cherry-pick --ff second && |
| 31 | test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)" |
| 32 | ' |
| 33 | |
| 34 | test_expect_success 'cherry-pick not using --ff does not fast forwards' ' |
| 35 | git checkout master && |
| 36 | git reset --hard first && |
| 37 | test_tick && |
| 38 | git cherry-pick second && |
| 39 | test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)" |
| 40 | ' |
| 41 | |
| 42 | # |
| 43 | # We setup the following graph: |
| 44 | # |
| 45 | # B---C |
| 46 | # / / |
| 47 | # first---A |
| 48 | # |
| 49 | # (This has been taken from t3502-cherry-pick-merge.sh) |
| 50 | # |
| 51 | test_expect_success 'merge setup' ' |
| 52 | git checkout master && |
| 53 | git reset --hard first && |
| 54 | echo new line >A && |
| 55 | git add A && |
| 56 | test_tick && |
| 57 | git commit -m "add line to A" A && |
| 58 | git tag A && |
| 59 | git checkout -b side first && |
| 60 | echo new line >B && |
| 61 | git add B && |
| 62 | test_tick && |
| 63 | git commit -m "add line to B" B && |
| 64 | git tag B && |
| 65 | git checkout master && |
| 66 | git merge side && |
| 67 | git tag C && |
| 68 | git checkout -b new A |
| 69 | ' |
| 70 | |
Sergey Organov | 1c32013 | 2018-12-14 07:53:51 +0300 | [diff] [blame] | 71 | test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' ' |
Christian Couder | b5c1a28 | 2010-03-06 21:34:43 +0100 | [diff] [blame] | 72 | git reset --hard A -- && |
Sergey Organov | 1c32013 | 2018-12-14 07:53:51 +0300 | [diff] [blame] | 73 | git cherry-pick --ff -m 1 B && |
| 74 | git diff --exit-code C -- |
Christian Couder | b5c1a28 | 2010-03-06 21:34:43 +0100 | [diff] [blame] | 75 | ' |
| 76 | |
| 77 | test_expect_success 'cherry pick a merge with --ff but without -m should fail' ' |
| 78 | git reset --hard A -- && |
| 79 | test_must_fail git cherry-pick --ff C && |
| 80 | git diff --exit-code A -- |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'cherry pick with --ff a merge (1)' ' |
| 84 | git reset --hard A -- && |
| 85 | git cherry-pick --ff -m 1 C && |
| 86 | git diff --exit-code C && |
| 87 | test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)" |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'cherry pick with --ff a merge (2)' ' |
| 91 | git reset --hard B -- && |
| 92 | git cherry-pick --ff -m 2 C && |
| 93 | git diff --exit-code C && |
| 94 | test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)" |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'cherry pick a merge relative to nonexistent parent with --ff should fail' ' |
| 98 | git reset --hard B -- && |
| 99 | test_must_fail git cherry-pick --ff -m 3 C |
| 100 | ' |
| 101 | |
Brandon Casey | 6355e50 | 2010-09-27 12:29:45 -0500 | [diff] [blame] | 102 | test_expect_success 'cherry pick a root commit with --ff' ' |
| 103 | git reset --hard first -- && |
| 104 | git rm file1 && |
| 105 | echo first >file2 && |
| 106 | git add file2 && |
| 107 | git commit --amend -m "file2" && |
| 108 | git cherry-pick --ff first && |
brian m. carlson | 19ce549 | 2019-08-18 19:16:40 +0000 | [diff] [blame] | 109 | test "$(git rev-parse --verify HEAD)" = "$(test_oid cp_ff)" |
Brandon Casey | 6355e50 | 2010-09-27 12:29:45 -0500 | [diff] [blame] | 110 | ' |
| 111 | |
Junio C Hamano | 7a96c38 | 2013-09-05 14:51:17 -0700 | [diff] [blame] | 112 | test_expect_success 'cherry-pick --ff on unborn branch' ' |
Martin von Zweigbergk | 334ae39 | 2012-12-21 11:10:11 -0800 | [diff] [blame] | 113 | git checkout --orphan unborn && |
| 114 | git rm --cached -r . && |
| 115 | rm -rf * && |
| 116 | git cherry-pick --ff first && |
| 117 | test_cmp_rev first HEAD |
| 118 | ' |
| 119 | |
Christian Couder | b5c1a28 | 2010-03-06 21:34:43 +0100 | [diff] [blame] | 120 | test_done |