3 # Copyright (c) 2006 Yann Dirson, based on t3400 by Amos Waterland
6 test_description
='git cherry should detect patches integrated upstream
8 This test cherry-picks one local change of two into main branch, and
9 checks that git cherry only returns the second patch in the local branch
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 GIT_AUTHOR_EMAIL
=bogus_email_address
17 export GIT_AUTHOR_EMAIL
20 'prepare repository with topic branch, and check cherry finds the 2 patches from there' \
22 git update-index --add A &&
24 git commit -m "Add A." &&
26 git checkout -b my-topic-branch &&
29 git update-index --add B &&
31 git commit -m "Add B." &&
33 echo AnotherSecond > C &&
34 git update-index --add C &&
36 git commit -m "Add C." &&
38 git checkout -f main &&
44 git commit -m "Modify A." &&
46 expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* + .*"
50 'check that cherry with limit returns only the top patch'\
51 'expr "$(echo $(git cherry main my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
55 'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' \
56 'git cherry-pick my-topic-branch^0 &&
57 echo $(git cherry main my-topic-branch) &&
58 expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* - .*"
61 test_expect_success
'cherry ignores whitespace' '
62 git switch --orphan=upstream-with-space &&
63 test_commit initial file &&
65 git switch --create=feature-without-space &&
67 # A spaceless file on the feature branch. Expect a match upstream.
70 git commit -m"file without space" &&
71 git log --format="- %H" -1 >>expect &&
73 # A further change. Should not match upstream.
74 test_commit change file &&
75 git log --format="+ %H" -1 >>expect &&
77 git switch upstream-with-space &&
78 # Same as the spaceless file, just with spaces and on upstream.
79 test_commit "file with space" file "s p a c e" file-with-space &&
80 git cherry upstream-with-space feature-without-space >actual &&
81 test_cmp expect actual