#!/bin/sh global test_description := ''cherry picking and reverting a merge b---c / / initial---a '' source ./test-lib.sh test_expect_success setup ' >A && >B && git add A B && git commit -m "Initial" && git tag initial && git branch side && echo new line >A && git commit -m "add line to A" A && git tag a && git checkout side && echo new line >B && git commit -m "add line to B" B && git tag b && git checkout master && git merge side && git tag c ' test_expect_success 'cherry-pick a non-merge with -m should fail' ' git reset --hard && git checkout a^0 && test_expect_code 128 git cherry-pick -m 1 b && git diff --exit-code a -- ' test_expect_success 'cherry pick a merge without -m should fail' ' git reset --hard && git checkout a^0 && test_must_fail git cherry-pick c && git diff --exit-code a -- ' test_expect_success 'cherry pick a merge (1)' ' git reset --hard && git checkout a^0 && git cherry-pick -m 1 c && git diff --exit-code c ' test_expect_success 'cherry pick a merge (2)' ' git reset --hard && git checkout b^0 && git cherry-pick -m 2 c && git diff --exit-code c ' test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' ' git reset --hard && git checkout b^0 && test_must_fail git cherry-pick -m 3 c ' test_expect_success 'revert a non-merge with -m should fail' ' git reset --hard && git checkout c^0 && test_must_fail git revert -m 1 b && git diff --exit-code c ' test_expect_success 'revert a merge without -m should fail' ' git reset --hard && git checkout c^0 && test_must_fail git revert c && git diff --exit-code c ' test_expect_success 'revert a merge (1)' ' git reset --hard && git checkout c^0 && git revert -m 1 c && git diff --exit-code a -- ' test_expect_success 'revert a merge (2)' ' git reset --hard && git checkout c^0 && git revert -m 2 c && git diff --exit-code b -- ' test_expect_success 'revert a merge relative to nonexistent parent should fail' ' git reset --hard && git checkout c^0 && test_must_fail git revert -m 3 c && git diff --exit-code c ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"cherry picking and reverting a merge\n"> <"\n"> <"\t\tb---c\n"> <"\t / /\n"> <"\tinitial---a\n"> <"\n"> ) } spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\n"> <"\t>A &&\n"> <"\t>B &&\n"> <"\tgit add A B &&\n"> <"\tgit commit -m \"Initial\" &&\n"> <"\tgit tag initial &&\n"> <"\tgit branch side &&\n"> <"\techo new line >A &&\n"> <"\tgit commit -m \"add line to A\" A &&\n"> <"\tgit tag a &&\n"> <"\tgit checkout side &&\n"> <"\techo new line >B &&\n"> <"\tgit commit -m \"add line to B\" B &&\n"> <"\tgit tag b &&\n"> <"\tgit checkout master &&\n"> <"\tgit merge side &&\n"> <"\tgit tag c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"cherry-pick a non-merge with -m should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout a^0 &&\n"> <"\ttest_expect_code 128 git cherry-pick -m 1 b &&\n"> <"\tgit diff --exit-code a --\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"cherry pick a merge without -m should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout a^0 &&\n"> <"\ttest_must_fail git cherry-pick c &&\n"> <"\tgit diff --exit-code a --\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"cherry pick a merge (1)">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout a^0 &&\n"> <"\tgit cherry-pick -m 1 c &&\n"> <"\tgit diff --exit-code c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"cherry pick a merge (2)">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout b^0 &&\n"> <"\tgit cherry-pick -m 2 c &&\n"> <"\tgit diff --exit-code c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"cherry pick a merge relative to nonexistent parent should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout b^0 &&\n"> <"\ttest_must_fail git cherry-pick -m 3 c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"revert a non-merge with -m should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout c^0 &&\n"> <"\ttest_must_fail git revert -m 1 b &&\n"> <"\tgit diff --exit-code c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"revert a merge without -m should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout c^0 &&\n"> <"\ttest_must_fail git revert c &&\n"> <"\tgit diff --exit-code c\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"revert a merge (1)">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout c^0 &&\n"> <"\tgit revert -m 1 c &&\n"> <"\tgit diff --exit-code a --\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"revert a merge (2)">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout c^0 &&\n"> <"\tgit revert -m 2 c &&\n"> <"\tgit diff --exit-code b --\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"revert a merge relative to nonexistent parent should fail">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout c^0 &&\n"> <"\ttest_must_fail git revert -m 3 c &&\n"> <"\tgit diff --exit-code c\n"> <"\n"> ) } ) (C {(test_done)}) ] )