The eleventh batch
[git/gitster.git] / t / t3505-cherry-pick-empty.sh
blobead3fb46807ef33427172dde75a45f5cfa01bfb0
1 #!/bin/sh
3 test_description='test cherry-picking an empty commit'
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 '
13 echo first > file1 &&
14 git add file1 &&
15 test_tick &&
16 git commit -m "first" &&
18 git checkout -b empty-message-branch &&
19 echo third >> file1 &&
20 git add file1 &&
21 test_tick &&
22 git commit --allow-empty-message -m "" &&
24 git checkout main &&
25 git checkout -b empty-change-branch &&
26 test_tick &&
27 git commit --allow-empty -m "empty"
31 test_expect_success 'cherry-pick an empty commit' '
32 git checkout main &&
33 test_expect_code 1 git cherry-pick empty-change-branch
36 test_expect_success 'index lockfile was removed' '
37 test ! -f .git/index.lock
40 test_expect_success 'cherry-pick a commit with an empty message' '
41 test_when_finished "git reset --hard empty-message-branch~1" &&
42 git checkout main &&
43 git cherry-pick empty-message-branch
46 test_expect_success 'index lockfile was removed' '
47 test ! -f .git/index.lock
50 test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
51 git checkout -f main &&
52 git cherry-pick --allow-empty-message empty-message-branch
55 test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
56 git checkout main &&
57 echo fourth >>file2 &&
58 git add file2 &&
59 git commit -m "fourth" &&
60 test_must_fail git cherry-pick empty-change-branch
63 test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
64 git checkout main &&
65 git cherry-pick --allow-empty empty-change-branch
68 test_expect_success 'cherry pick with --keep-redundant-commits' '
69 git checkout main &&
70 git cherry-pick --keep-redundant-commits HEAD^
73 test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
74 git checkout main &&
75 git branch fork &&
76 echo foo >file2 &&
77 git add file2 &&
78 test_tick &&
79 git commit -m "add file2 on main" &&
81 git checkout fork &&
82 echo foo >file2 &&
83 git add file2 &&
84 test_tick &&
85 git commit -m "add file2 on the side"
88 test_expect_success 'cherry-pick a no-op with neither --keep-redundant nor --empty' '
89 git reset --hard &&
90 git checkout fork^0 &&
91 test_must_fail git cherry-pick main
94 test_expect_success 'cherry-pick a no-op with --keep-redundant' '
95 git reset --hard &&
96 git checkout fork^0 &&
97 git cherry-pick --keep-redundant-commits main &&
98 git show -s --format=%s >actual &&
99 echo "add file2 on main" >expect &&
100 test_cmp expect actual
103 test_expect_success '--keep-redundant-commits is incompatible with operations' '
104 test_must_fail git cherry-pick HEAD 2>output &&
105 test_grep "The previous cherry-pick is now empty" output &&
106 test_must_fail git cherry-pick --keep-redundant-commits --continue 2>output &&
107 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --continue" output &&
108 test_must_fail git cherry-pick --keep-redundant-commits --skip 2>output &&
109 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --skip" output &&
110 test_must_fail git cherry-pick --keep-redundant-commits --abort 2>output &&
111 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --abort" output &&
112 test_must_fail git cherry-pick --keep-redundant-commits --quit 2>output &&
113 test_grep "fatal: cherry-pick: --keep-redundant-commits cannot be used with --quit" output &&
114 git cherry-pick --abort
117 test_expect_success '--empty is incompatible with operations' '
118 test_must_fail git cherry-pick HEAD 2>output &&
119 test_grep "The previous cherry-pick is now empty" output &&
120 test_must_fail git cherry-pick --empty=stop --continue 2>output &&
121 test_grep "fatal: cherry-pick: --empty cannot be used with --continue" output &&
122 test_must_fail git cherry-pick --empty=stop --skip 2>output &&
123 test_grep "fatal: cherry-pick: --empty cannot be used with --skip" output &&
124 test_must_fail git cherry-pick --empty=stop --abort 2>output &&
125 test_grep "fatal: cherry-pick: --empty cannot be used with --abort" output &&
126 test_must_fail git cherry-pick --empty=stop --quit 2>output &&
127 test_grep "fatal: cherry-pick: --empty cannot be used with --quit" output &&
128 git cherry-pick --abort
131 test_expect_success 'cherry-pick a no-op with --empty=stop' '
132 git reset --hard &&
133 git checkout fork^0 &&
134 test_must_fail git cherry-pick --empty=stop main 2>output &&
135 test_grep "The previous cherry-pick is now empty" output
138 test_expect_success 'cherry-pick a no-op with --empty=drop' '
139 git reset --hard &&
140 git checkout fork^0 &&
141 git cherry-pick --empty=drop main &&
142 test_commit_message HEAD -m "add file2 on the side"
145 test_expect_success 'cherry-pick a no-op with --empty=keep' '
146 git reset --hard &&
147 git checkout fork^0 &&
148 git cherry-pick --empty=keep main &&
149 test_commit_message HEAD -m "add file2 on main"
152 test_done