1#!/bin/sh 2 3test_description='test cherry-picking (and reverting) a root commit' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 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 17 git symbolic-ref HEAD refs/heads/second && 18 rm .git/index file1 && 19 echo second > file2 && 20 git add file2 && 21 test_tick && 22 git commit -m "second" && 23 24 git symbolic-ref HEAD refs/heads/third && 25 rm .git/index file2 && 26 echo third > file3 && 27 git add file3 && 28 test_tick && 29 git commit -m "third" 30 31' 32 33test_expect_success 'cherry-pick a root commit' ' 34 35 git checkout second^0 && 36 git cherry-pick main && 37 echo first >expect && 38 test_cmp expect file1 39 40' 41 42test_expect_success 'revert a root commit' ' 43 44 git revert main && 45 test_path_is_missing file1 46 47' 48 49test_expect_success 'cherry-pick a root commit with an external strategy' ' 50 51 git cherry-pick --strategy=resolve main && 52 echo first >expect && 53 test_cmp expect file1 54 55' 56 57test_expect_success 'revert a root commit with an external strategy' ' 58 59 git revert --strategy=resolve main && 60 test_path_is_missing file1 61 62' 63 64test_expect_success 'cherry-pick two root commits' ' 65 66 echo first >expect.file1 && 67 echo second >expect.file2 && 68 echo third >expect.file3 && 69 70 git checkout second^0 && 71 git cherry-pick main third && 72 73 test_cmp expect.file1 file1 && 74 test_cmp expect.file2 file2 && 75 test_cmp expect.file3 file3 && 76 git rev-parse --verify HEAD^^ && 77 test_must_fail git rev-parse --verify HEAD^^^ 78 79' 80 81test_done 82