diff options
Diffstat (limited to 't/t3507-cherry-pick-conflict.sh')
-rwxr-xr-x | t/t3507-cherry-pick-conflict.sh | 109 |
1 files changed, 69 insertions, 40 deletions
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 9b9b4ca8d4..979e843c65 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -9,6 +9,9 @@ test_description='test cherry-pick and revert with conflicts ' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh pristine_detach () { @@ -29,7 +32,7 @@ test_expect_success setup ' test_commit redundant-pick foo c redundant && git commit --allow-empty --allow-empty-message && git tag empty && - git checkout master && + git checkout main && git config advice.detachedhead false ' @@ -44,20 +47,23 @@ test_expect_success 'failed cherry-pick does not advance HEAD' ' test "$head" = "$newhead" ' -test_expect_success 'advice from failed cherry-pick' " +test_expect_success 'advice from failed cherry-pick' ' pristine_detach initial && - picked=\$(git rev-parse --short picked) && + picked=$(git rev-parse --short picked) && cat <<-EOF >expected && - error: could not apply \$picked... picked - hint: after resolving the conflicts, mark the corrected paths - hint: with 'git add <paths>' or 'git rm <paths>' - hint: and commit the result with 'git commit' + error: could not apply $picked... picked + hint: After resolving the conflicts, mark them with + hint: "git add/rm <pathspec>", then run + hint: "git cherry-pick --continue". + hint: You can instead skip this commit with "git cherry-pick --skip". + hint: To abort and get back to the state before "git cherry-pick", + hint: run "git cherry-pick --abort". EOF test_must_fail git cherry-pick picked 2>actual && - test_i18ncmp expected actual -" + test_cmp expected actual +' test_expect_success 'advice from failed cherry-pick --no-commit' " pristine_detach initial && @@ -70,7 +76,7 @@ test_expect_success 'advice from failed cherry-pick --no-commit' " EOF test_must_fail git cherry-pick --no-commit picked 2>actual && - test_i18ncmp expected actual + test_cmp expected actual " test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' @@ -161,6 +167,29 @@ test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' test_must_fail git rev-parse --verify CHERRY_PICK_HEAD ' + +test_expect_success 'partial commit of cherry-pick fails' ' + pristine_detach initial && + + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + test_must_fail git commit foo 2>err && + + test_i18ngrep "cannot do a partial commit during a cherry-pick." err +' + +test_expect_success 'commit --amend of cherry-pick fails' ' + pristine_detach initial && + + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + test_must_fail git commit --amend 2>err && + + test_i18ngrep "in the middle of a cherry-pick -- cannot amend." err +' + test_expect_success 'successful final commit clears cherry-pick state' ' pristine_detach initial && @@ -168,7 +197,7 @@ test_expect_success 'successful final commit clears cherry-pick state' ' echo resolved >foo && test_path_is_file .git/sequencer/todo && git commit -a && - test_must_fail test_path_exists .git/sequencer + test_path_is_missing .git/sequencer ' test_expect_success 'reset after final pick clears cherry-pick state' ' @@ -178,7 +207,7 @@ test_expect_success 'reset after final pick clears cherry-pick state' ' echo resolved >foo && test_path_is_file .git/sequencer/todo && git reset && - test_must_fail test_path_exists .git/sequencer + test_path_is_missing .git/sequencer ' test_expect_success 'failed cherry-pick produces dirty index' ' @@ -230,7 +259,7 @@ test_expect_success \ test_must_fail git cherry-pick picked && - test_i18ncmp expected .git/MERGE_MSG + test_cmp expected .git/MERGE_MSG ' test_expect_success \ @@ -250,7 +279,7 @@ test_expect_success \ test_must_fail git cherry-pick --cleanup=scissors picked && - test_i18ncmp expected .git/MERGE_MSG + test_cmp expected .git/MERGE_MSG ' test_expect_success 'failed cherry-pick describes conflict in work tree' ' @@ -260,12 +289,12 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' ' a ======= c - >>>>>>> objid picked + >>>>>>> objid (picked) EOF test_must_fail git cherry-pick picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && + sed "s/[a-f0-9]* (/objid (/" foo >actual && test_cmp expected actual ' @@ -275,16 +304,16 @@ test_expect_success 'diff3 -m style' ' cat <<-EOF >expected && <<<<<<< HEAD a - ||||||| parent of objid picked + ||||||| parent of objid (picked) b ======= c - >>>>>>> objid picked + >>>>>>> objid (picked) EOF test_must_fail git cherry-pick picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && + sed "s/[a-f0-9]* (/objid (/" foo >actual && test_cmp expected actual ' @@ -296,7 +325,7 @@ test_expect_success 'revert also handles conflicts sanely' ' a ======= b - >>>>>>> parent of objid picked + >>>>>>> parent of objid (picked) EOF { git checkout picked -- foo && @@ -322,7 +351,7 @@ test_expect_success 'revert also handles conflicts sanely' ' test_must_fail git update-index --refresh -q && test_must_fail git diff-index --exit-code HEAD && test_cmp expected-stages actual-stages && - sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && + sed "s/[a-f0-9]* (/objid (/" foo >actual && test_cmp expected actual ' @@ -381,23 +410,23 @@ test_expect_success 'failed commit does not clear REVERT_HEAD' ' ' test_expect_success 'successful final commit clears revert state' ' - pristine_detach picked-signed && + pristine_detach picked-signed && - test_must_fail git revert picked-signed base && - echo resolved >foo && - test_path_is_file .git/sequencer/todo && - git commit -a && - test_must_fail test_path_exists .git/sequencer + test_must_fail git revert picked-signed base && + echo resolved >foo && + test_path_is_file .git/sequencer/todo && + git commit -a && + test_path_is_missing .git/sequencer ' test_expect_success 'reset after final pick clears revert state' ' - pristine_detach picked-signed && + pristine_detach picked-signed && - test_must_fail git revert picked-signed base && - echo resolved >foo && - test_path_is_file .git/sequencer/todo && - git reset && - test_must_fail test_path_exists .git/sequencer + test_must_fail git revert picked-signed base && + echo resolved >foo && + test_path_is_file .git/sequencer/todo && + git reset && + test_path_is_missing .git/sequencer ' test_expect_success 'revert conflict, diff3 -m style' ' @@ -406,16 +435,16 @@ test_expect_success 'revert conflict, diff3 -m style' ' cat <<-EOF >expected && <<<<<<< HEAD a - ||||||| objid picked + ||||||| objid (picked) c ======= b - >>>>>>> parent of objid picked + >>>>>>> parent of objid (picked) EOF test_must_fail git revert picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && + sed "s/[a-f0-9]* (/objid (/" foo >actual && test_cmp expected actual ' @@ -439,7 +468,7 @@ test_expect_success \ test_must_fail git revert picked && sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && - test_i18ncmp expected actual + test_cmp expected actual ' test_expect_success \ @@ -462,7 +491,7 @@ test_expect_success \ test_must_fail git revert --cleanup=scissors picked && sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && - test_i18ncmp expected actual + test_cmp expected actual ' test_expect_success 'failed cherry-pick does not forget -s' ' @@ -489,7 +518,7 @@ test_expect_success 'commit after failed cherry-pick adds -s at the right place' Signed-off-by: C O Mitter <committer@example.com> # Conflicts: EOF - grep -e "^# Conflicts:" -e '^Signed-off-by' .git/COMMIT_EDITMSG >actual && + grep -e "^# Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual && test_cmp expect actual && cat <<-\EOF >expected && @@ -518,7 +547,7 @@ test_expect_success 'commit --amend -s places the sign-off at the right place' ' Signed-off-by: C O Mitter <committer@example.com> Conflicts: EOF - grep -e "^Conflicts:" -e '^Signed-off-by' .git/COMMIT_EDITMSG >actual && + grep -e "^Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual && test_cmp expect actual ' |