Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test cherry-picking an empty commit' |
| 4 | |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | |
| 12 | echo first > file1 && |
| 13 | git add file1 && |
| 14 | test_tick && |
| 15 | git commit -m "first" && |
| 16 | |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 17 | git checkout -b empty-message-branch && |
Christian Couder | 2c048a3 | 2010-07-22 15:18:29 +0200 | [diff] [blame] | 18 | echo third >> file1 && |
| 19 | git add file1 && |
| 20 | test_tick && |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 21 | git commit --allow-empty-message -m "" && |
| 22 | |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 23 | git checkout main && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 24 | git checkout -b empty-change-branch && |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 25 | test_tick && |
| 26 | git commit --allow-empty -m "empty" |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 27 | |
| 28 | ' |
| 29 | |
Junio C Hamano | c6720cf | 2009-06-21 02:01:28 -0700 | [diff] [blame] | 30 | test_expect_success 'cherry-pick an empty commit' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 31 | git checkout main && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 32 | test_expect_code 1 git cherry-pick empty-change-branch |
Christian Couder | 2c048a3 | 2010-07-22 15:18:29 +0200 | [diff] [blame] | 33 | ' |
| 34 | |
| 35 | test_expect_success 'index lockfile was removed' ' |
Christian Couder | 2c048a3 | 2010-07-22 15:18:29 +0200 | [diff] [blame] | 36 | test ! -f .git/index.lock |
Christian Couder | 2c048a3 | 2010-07-22 15:18:29 +0200 | [diff] [blame] | 37 | ' |
| 38 | |
| 39 | test_expect_success 'cherry-pick a commit with an empty message' ' |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 40 | test_when_finished "git reset --hard empty-message-branch~1" && |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 41 | git checkout main && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 42 | git cherry-pick empty-message-branch |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 43 | ' |
| 44 | |
| 45 | test_expect_success 'index lockfile was removed' ' |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 46 | test ! -f .git/index.lock |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 47 | ' |
| 48 | |
Chris Webb | 4bee958 | 2012-08-02 11:38:51 +0100 | [diff] [blame] | 49 | test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 50 | git checkout -f main && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 51 | git cherry-pick --allow-empty-message empty-message-branch |
Chris Webb | 4bee958 | 2012-08-02 11:38:51 +0100 | [diff] [blame] | 52 | ' |
| 53 | |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 54 | test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 55 | git checkout main && |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 56 | echo fourth >>file2 && |
| 57 | git add file2 && |
| 58 | git commit -m "fourth" && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 59 | test_must_fail git cherry-pick empty-change-branch |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 60 | ' |
| 61 | |
| 62 | test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 63 | git checkout main && |
Elijah Newren | a3ec9ea | 2018-09-12 14:18:48 -0700 | [diff] [blame] | 64 | git cherry-pick --allow-empty empty-change-branch |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 65 | ' |
| 66 | |
| 67 | test_expect_success 'cherry pick with --keep-redundant-commits' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 68 | git checkout main && |
Neil Horman | bedfe86 | 2012-04-20 10:36:16 -0400 | [diff] [blame] | 69 | git cherry-pick --keep-redundant-commits HEAD^ |
| 70 | ' |
| 71 | |
Junio C Hamano | ac2b0e8 | 2012-05-29 17:14:41 -0700 | [diff] [blame] | 72 | test_expect_success 'cherry-pick a commit that becomes no-op (prep)' ' |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 73 | git checkout main && |
Junio C Hamano | ac2b0e8 | 2012-05-29 17:14:41 -0700 | [diff] [blame] | 74 | git branch fork && |
| 75 | echo foo >file2 && |
| 76 | git add file2 && |
| 77 | test_tick && |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 78 | git commit -m "add file2 on main" && |
Junio C Hamano | ac2b0e8 | 2012-05-29 17:14:41 -0700 | [diff] [blame] | 79 | |
| 80 | git checkout fork && |
| 81 | echo foo >file2 && |
| 82 | git add file2 && |
| 83 | test_tick && |
| 84 | git commit -m "add file2 on the side" |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'cherry-pick a no-op without --keep-redundant' ' |
| 88 | git reset --hard && |
| 89 | git checkout fork^0 && |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 90 | test_must_fail git cherry-pick main |
Junio C Hamano | ac2b0e8 | 2012-05-29 17:14:41 -0700 | [diff] [blame] | 91 | ' |
| 92 | |
| 93 | test_expect_success 'cherry-pick a no-op with --keep-redundant' ' |
| 94 | git reset --hard && |
| 95 | git checkout fork^0 && |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 96 | git cherry-pick --keep-redundant-commits main && |
Felipe Contreras | 15c7348 | 2013-05-28 07:54:29 -0500 | [diff] [blame] | 97 | git show -s --format=%s >actual && |
Johannes Schindelin | cbc75a1 | 2020-11-18 23:44:26 +0000 | [diff] [blame] | 98 | echo "add file2 on main" >expect && |
Junio C Hamano | ac2b0e8 | 2012-05-29 17:14:41 -0700 | [diff] [blame] | 99 | test_cmp expect actual |
| 100 | ' |
| 101 | |
Chris Johnsen | 0d66e95 | 2009-03-07 03:30:51 -0600 | [diff] [blame] | 102 | test_done |