]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3505-cherry-pick-empty.sh
The third batch
[thirdparty/git.git] / t / t3505-cherry-pick-empty.sh
CommitLineData
0d66e959
CJ
1#!/bin/sh
2
3test_description='test cherry-picking an empty commit'
4
cbc75a12 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
0d66e959
CJ
8. ./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
a3ec9eaf 17 git checkout -b empty-message-branch &&
2c048a30
CC
18 echo third >> file1 &&
19 git add file1 &&
20 test_tick &&
bedfe86c
NH
21 git commit --allow-empty-message -m "" &&
22
cbc75a12 23 git checkout main &&
a3ec9eaf 24 git checkout -b empty-change-branch &&
bedfe86c
NH
25 test_tick &&
26 git commit --allow-empty -m "empty"
0d66e959
CJ
27
28'
29
c6720cfa 30test_expect_success 'cherry-pick an empty commit' '
cbc75a12 31 git checkout main &&
a3ec9eaf 32 test_expect_code 1 git cherry-pick empty-change-branch
2c048a30
CC
33'
34
35test_expect_success 'index lockfile was removed' '
2c048a30 36 test ! -f .git/index.lock
2c048a30
CC
37'
38
39test_expect_success 'cherry-pick a commit with an empty message' '
a3ec9eaf 40 test_when_finished "git reset --hard empty-message-branch~1" &&
cbc75a12 41 git checkout main &&
a3ec9eaf 42 git cherry-pick empty-message-branch
0d66e959
CJ
43'
44
45test_expect_success 'index lockfile was removed' '
0d66e959 46 test ! -f .git/index.lock
0d66e959
CJ
47'
48
4bee9584 49test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
cbc75a12 50 git checkout -f main &&
a3ec9eaf 51 git cherry-pick --allow-empty-message empty-message-branch
4bee9584
CW
52'
53
bedfe86c 54test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
cbc75a12 55 git checkout main &&
bedfe86c
NH
56 echo fourth >>file2 &&
57 git add file2 &&
58 git commit -m "fourth" &&
a3ec9eaf 59 test_must_fail git cherry-pick empty-change-branch
bedfe86c
NH
60'
61
62test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
cbc75a12 63 git checkout main &&
a3ec9eaf 64 git cherry-pick --allow-empty empty-change-branch
bedfe86c
NH
65'
66
67test_expect_success 'cherry pick with --keep-redundant-commits' '
cbc75a12 68 git checkout main &&
bedfe86c
NH
69 git cherry-pick --keep-redundant-commits HEAD^
70'
71
ac2b0e8f 72test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
cbc75a12 73 git checkout main &&
ac2b0e8f
JH
74 git branch fork &&
75 echo foo >file2 &&
76 git add file2 &&
77 test_tick &&
cbc75a12 78 git commit -m "add file2 on main" &&
ac2b0e8f
JH
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
ec79d763 87test_expect_success 'cherry-pick a no-op with neither --keep-redundant nor --empty' '
ac2b0e8f
JH
88 git reset --hard &&
89 git checkout fork^0 &&
cbc75a12 90 test_must_fail git cherry-pick main
ac2b0e8f
JH
91'
92
93test_expect_success 'cherry-pick a no-op with --keep-redundant' '
94 git reset --hard &&
95 git checkout fork^0 &&
cbc75a12 96 git cherry-pick --keep-redundant-commits main &&
15c7348e 97 git show -s --format=%s >actual &&
cbc75a12 98 echo "add file2 on main" >expect &&
ac2b0e8f
JH
99 test_cmp expect actual
100'
101
bd2f9fd0
BL
102test_expect_success '--keep-redundant-commits is incompatible with operations' '
103 test_must_fail git cherry-pick HEAD 2>output &&
104 test_grep "The previous cherry-pick is now empty" output &&
105 test_must_fail git cherry-pick --keep-redundant-commits --continue 2>output &&
106 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --continue" output &&
107 test_must_fail git cherry-pick --keep-redundant-commits --skip 2>output &&
108 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --skip" output &&
109 test_must_fail git cherry-pick --keep-redundant-commits --abort 2>output &&
110 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --abort" output &&
111 test_must_fail git cherry-pick --keep-redundant-commits --quit 2>output &&
112 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --quit" output &&
113 git cherry-pick --abort
114'
115
ec79d763
BL
116test_expect_success '--empty is incompatible with operations' '
117 test_must_fail git cherry-pick HEAD 2>output &&
118 test_grep "The previous cherry-pick is now empty" output &&
119 test_must_fail git cherry-pick --empty=stop --continue 2>output &&
120 test_grep "fatal: cherry-pick: --empty cannot be used with --continue" output &&
121 test_must_fail git cherry-pick --empty=stop --skip 2>output &&
122 test_grep "fatal: cherry-pick: --empty cannot be used with --skip" output &&
123 test_must_fail git cherry-pick --empty=stop --abort 2>output &&
124 test_grep "fatal: cherry-pick: --empty cannot be used with --abort" output &&
125 test_must_fail git cherry-pick --empty=stop --quit 2>output &&
126 test_grep "fatal: cherry-pick: --empty cannot be used with --quit" output &&
127 git cherry-pick --abort
128'
129
130test_expect_success 'cherry-pick a no-op with --empty=stop' '
131 git reset --hard &&
132 git checkout fork^0 &&
133 test_must_fail git cherry-pick --empty=stop main 2>output &&
134 test_grep "The previous cherry-pick is now empty" output
135'
136
137test_expect_success 'cherry-pick a no-op with --empty=drop' '
138 git reset --hard &&
139 git checkout fork^0 &&
140 git cherry-pick --empty=drop main &&
141 test_commit_message HEAD -m "add file2 on the side"
142'
143
144test_expect_success 'cherry-pick a no-op with --empty=keep' '
145 git reset --hard &&
146 git checkout fork^0 &&
147 git cherry-pick --empty=keep main &&
148 test_commit_message HEAD -m "add file2 on main"
149'
150
0d66e959 151test_done