blob: eba3c38d5ad861a5d71b7fa9615ee804b24e6fc4 [file] [log] [blame]
Chris Johnsen0d66e952009-03-07 03:30:51 -06001#!/bin/sh
2
3test_description='test cherry-picking an empty commit'
4
Johannes Schindelincbc75a12020-11-18 23:44:26 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Chris Johnsen0d66e952009-03-07 03:30:51 -06008. ./test-lib.sh
9
10test_expect_success setup '
11
12 echo first > file1 &&
13 git add file1 &&
14 test_tick &&
15 git commit -m "first" &&
16
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070017 git checkout -b empty-message-branch &&
Christian Couder2c048a32010-07-22 15:18:29 +020018 echo third >> file1 &&
19 git add file1 &&
20 test_tick &&
Neil Hormanbedfe862012-04-20 10:36:16 -040021 git commit --allow-empty-message -m "" &&
22
Johannes Schindelincbc75a12020-11-18 23:44:26 +000023 git checkout main &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070024 git checkout -b empty-change-branch &&
Neil Hormanbedfe862012-04-20 10:36:16 -040025 test_tick &&
26 git commit --allow-empty -m "empty"
Chris Johnsen0d66e952009-03-07 03:30:51 -060027
28'
29
Junio C Hamanoc6720cf2009-06-21 02:01:28 -070030test_expect_success 'cherry-pick an empty commit' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000031 git checkout main &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070032 test_expect_code 1 git cherry-pick empty-change-branch
Christian Couder2c048a32010-07-22 15:18:29 +020033'
34
35test_expect_success 'index lockfile was removed' '
Christian Couder2c048a32010-07-22 15:18:29 +020036 test ! -f .git/index.lock
Christian Couder2c048a32010-07-22 15:18:29 +020037'
38
39test_expect_success 'cherry-pick a commit with an empty message' '
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070040 test_when_finished "git reset --hard empty-message-branch~1" &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000041 git checkout main &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070042 git cherry-pick empty-message-branch
Chris Johnsen0d66e952009-03-07 03:30:51 -060043'
44
45test_expect_success 'index lockfile was removed' '
Chris Johnsen0d66e952009-03-07 03:30:51 -060046 test ! -f .git/index.lock
Chris Johnsen0d66e952009-03-07 03:30:51 -060047'
48
Chris Webb4bee9582012-08-02 11:38:51 +010049test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000050 git checkout -f main &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070051 git cherry-pick --allow-empty-message empty-message-branch
Chris Webb4bee9582012-08-02 11:38:51 +010052'
53
Neil Hormanbedfe862012-04-20 10:36:16 -040054test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000055 git checkout main &&
Neil Hormanbedfe862012-04-20 10:36:16 -040056 echo fourth >>file2 &&
57 git add file2 &&
58 git commit -m "fourth" &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070059 test_must_fail git cherry-pick empty-change-branch
Neil Hormanbedfe862012-04-20 10:36:16 -040060'
61
62test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000063 git checkout main &&
Elijah Newrena3ec9ea2018-09-12 14:18:48 -070064 git cherry-pick --allow-empty empty-change-branch
Neil Hormanbedfe862012-04-20 10:36:16 -040065'
66
67test_expect_success 'cherry pick with --keep-redundant-commits' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000068 git checkout main &&
Neil Hormanbedfe862012-04-20 10:36:16 -040069 git cherry-pick --keep-redundant-commits HEAD^
70'
71
Junio C Hamanoac2b0e82012-05-29 17:14:41 -070072test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
Johannes Schindelincbc75a12020-11-18 23:44:26 +000073 git checkout main &&
Junio C Hamanoac2b0e82012-05-29 17:14:41 -070074 git branch fork &&
75 echo foo >file2 &&
76 git add file2 &&
77 test_tick &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000078 git commit -m "add file2 on main" &&
Junio C Hamanoac2b0e82012-05-29 17:14:41 -070079
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
87test_expect_success 'cherry-pick a no-op without --keep-redundant' '
88 git reset --hard &&
89 git checkout fork^0 &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000090 test_must_fail git cherry-pick main
Junio C Hamanoac2b0e82012-05-29 17:14:41 -070091'
92
93test_expect_success 'cherry-pick a no-op with --keep-redundant' '
94 git reset --hard &&
95 git checkout fork^0 &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000096 git cherry-pick --keep-redundant-commits main &&
Felipe Contreras15c73482013-05-28 07:54:29 -050097 git show -s --format=%s >actual &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000098 echo "add file2 on main" >expect &&
Junio C Hamanoac2b0e82012-05-29 17:14:41 -070099 test_cmp expect actual
100'
101
Chris Johnsen0d66e952009-03-07 03:30:51 -0600102test_done