Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t3500-cherry.sh
blob61ca87512d59dcc37a831619cb6691af97fa7d25
1 #!/bin/sh
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
14 TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
17 GIT_AUTHOR_EMAIL=bogus_email_address
18 export GIT_AUTHOR_EMAIL
20 test_expect_success 'prepare repository with topic branch, and check cherry finds the 2 patches from there' '
21 echo First > A &&
22 git update-index --add A &&
23 test_tick &&
24 git commit -m "Add A." &&
26 git checkout -b my-topic-branch &&
28 echo Second > B &&
29 git update-index --add B &&
30 test_tick &&
31 git commit -m "Add B." &&
33 echo AnotherSecond > C &&
34 git update-index --add C &&
35 test_tick &&
36 git commit -m "Add C." &&
38 git checkout -f main &&
39 rm -f B C &&
41 echo Third >> A &&
42 git update-index A &&
43 test_tick &&
44 git commit -m "Modify A." &&
46 expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* + .*"
49 test_expect_success 'check that cherry with limit returns only the top patch' '
50 expr "$(echo $(git cherry main my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
53 test_expect_success 'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' '
54 git cherry-pick my-topic-branch^0 &&
55 echo $(git cherry main my-topic-branch) &&
56 expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* - .*"
59 test_expect_success 'cherry ignores whitespace' '
60 git switch --orphan=upstream-with-space &&
61 test_commit initial file &&
62 >expect &&
63 git switch --create=feature-without-space &&
65 # A spaceless file on the feature branch. Expect a match upstream.
66 printf space >file &&
67 git add file &&
68 git commit -m"file without space" &&
69 git log --format="- %H" -1 >>expect &&
71 # A further change. Should not match upstream.
72 test_commit change file &&
73 git log --format="+ %H" -1 >>expect &&
75 git switch upstream-with-space &&
76 # Same as the spaceless file, just with spaces and on upstream.
77 test_commit "file with space" file "s p a c e" file-with-space &&
78 git cherry upstream-with-space feature-without-space >actual &&
79 test_cmp expect actual
82 test_done