t4129: don't fail if setgid is set in the test directory
[git] / t / t3500-cherry.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Yann Dirson, based on t3400 by Amos Waterland
4 #
5
6 test_description='git cherry should detect patches integrated upstream
7
8 This test cherry-picks one local change of two into master branch, and
9 checks that git cherry only returns the second patch in the local branch
10 '
11 . ./test-lib.sh
12
13 GIT_AUTHOR_EMAIL=bogus_email_address
14 export GIT_AUTHOR_EMAIL
15
16 test_expect_success \
17     'prepare repository with topic branch, and check cherry finds the 2 patches from there' \
18     'echo First > A &&
19      git update-index --add A &&
20      test_tick &&
21      git commit -m "Add A." &&
22
23      git checkout -b my-topic-branch &&
24
25      echo Second > B &&
26      git update-index --add B &&
27      test_tick &&
28      git commit -m "Add B." &&
29
30      echo AnotherSecond > C &&
31      git update-index --add C &&
32      test_tick &&
33      git commit -m "Add C." &&
34
35      git checkout -f master &&
36      rm -f B C &&
37
38      echo Third >> A &&
39      git update-index A &&
40      test_tick &&
41      git commit -m "Modify A." &&
42
43      expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* + .*"
44 '
45
46 test_expect_success \
47     'check that cherry with limit returns only the top patch'\
48     'expr "$(echo $(git cherry master my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
49 '
50
51 test_expect_success \
52     'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' \
53     'git cherry-pick my-topic-branch^0 &&
54      echo $(git cherry master my-topic-branch) &&
55      expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
56 '
57
58 test_expect_success 'cherry ignores whitespace' '
59         git switch --orphan=upstream-with-space &&
60         test_commit initial file &&
61         >expect &&
62         git switch --create=feature-without-space &&
63
64         # A spaceless file on the feature branch.  Expect a match upstream.
65         printf space >file &&
66         git add file &&
67         git commit -m"file without space" &&
68         git log --format="- %H" -1 >>expect &&
69
70         # A further change.  Should not match upstream.
71         test_commit change file &&
72         git log --format="+ %H" -1 >>expect &&
73
74         git switch upstream-with-space &&
75         # Same as the spaceless file, just with spaces and on upstream.
76         test_commit "file with space" file "s p a c e" file-with-space &&
77         git cherry upstream-with-space feature-without-space >actual &&
78         test_cmp expect actual
79 '
80
81 test_done