Merge branch 'jc/tree-walk-drop-base-offset'
[git/debian.git] / t / t3505-cherry-pick-empty.sh
blobeba3c38d5ad861a5d71b7fa9615ee804b24e6fc4
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-lib.sh
10 test_expect_success setup '
12 echo first > file1 &&
13 git add file1 &&
14 test_tick &&
15 git commit -m "first" &&
17 git checkout -b empty-message-branch &&
18 echo third >> file1 &&
19 git add file1 &&
20 test_tick &&
21 git commit --allow-empty-message -m "" &&
23 git checkout main &&
24 git checkout -b empty-change-branch &&
25 test_tick &&
26 git commit --allow-empty -m "empty"
30 test_expect_success 'cherry-pick an empty commit' '
31 git checkout main &&
32 test_expect_code 1 git cherry-pick empty-change-branch
35 test_expect_success 'index lockfile was removed' '
36 test ! -f .git/index.lock
39 test_expect_success 'cherry-pick a commit with an empty message' '
40 test_when_finished "git reset --hard empty-message-branch~1" &&
41 git checkout main &&
42 git cherry-pick empty-message-branch
45 test_expect_success 'index lockfile was removed' '
46 test ! -f .git/index.lock
49 test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
50 git checkout -f main &&
51 git cherry-pick --allow-empty-message empty-message-branch
54 test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
55 git checkout main &&
56 echo fourth >>file2 &&
57 git add file2 &&
58 git commit -m "fourth" &&
59 test_must_fail git cherry-pick empty-change-branch
62 test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
63 git checkout main &&
64 git cherry-pick --allow-empty empty-change-branch
67 test_expect_success 'cherry pick with --keep-redundant-commits' '
68 git checkout main &&
69 git cherry-pick --keep-redundant-commits HEAD^
72 test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
73 git checkout main &&
74 git branch fork &&
75 echo foo >file2 &&
76 git add file2 &&
77 test_tick &&
78 git commit -m "add file2 on main" &&
80 git checkout fork &&
81 echo foo >file2 &&
82 git add file2 &&
83 test_tick &&
84 git commit -m "add file2 on the side"
87 test_expect_success 'cherry-pick a no-op without --keep-redundant' '
88 git reset --hard &&
89 git checkout fork^0 &&
90 test_must_fail git cherry-pick main
93 test_expect_success 'cherry-pick a no-op with --keep-redundant' '
94 git reset --hard &&
95 git checkout fork^0 &&
96 git cherry-pick --keep-redundant-commits main &&
97 git show -s --format=%s >actual &&
98 echo "add file2 on main" >expect &&
99 test_cmp expect actual
102 test_done