2006-01-08 00:38:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Yann Dirson, based on t3400 by Amos Waterland
|
|
|
|
#
|
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
test_description='git cherry should detect patches integrated upstream
|
2006-01-08 00:38:15 +00:00
|
|
|
|
|
|
|
This test cherry-picks one local change of two into master branch, and
|
2007-07-03 05:52:14 +00:00
|
|
|
checks that git cherry only returns the second patch in the local branch
|
2006-01-08 00:38:15 +00:00
|
|
|
'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2008-05-04 05:37:58 +00:00
|
|
|
GIT_AUTHOR_EMAIL=bogus_email_address
|
|
|
|
export GIT_AUTHOR_EMAIL
|
2006-01-08 00:38:15 +00:00
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'prepare repository with topic branch, and check cherry finds the 2 patches from there' \
|
|
|
|
'echo First > A &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index --add A &&
|
2010-04-07 00:08:54 +00:00
|
|
|
test_tick &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git commit -m "Add A." &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
2008-09-03 08:59:27 +00:00
|
|
|
git checkout -b my-topic-branch &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
|
|
|
echo Second > B &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index --add B &&
|
2010-04-07 00:08:54 +00:00
|
|
|
test_tick &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git commit -m "Add B." &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
|
|
|
echo AnotherSecond > C &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index --add C &&
|
2010-04-07 00:08:54 +00:00
|
|
|
test_tick &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git commit -m "Add C." &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
2008-09-03 08:59:27 +00:00
|
|
|
git checkout -f master &&
|
2006-05-17 08:17:46 +00:00
|
|
|
rm -f B C &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
|
|
|
echo Third >> A &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index A &&
|
2010-04-07 00:08:54 +00:00
|
|
|
test_tick &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git commit -m "Modify A." &&
|
2006-01-08 00:38:15 +00:00
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* + .*"
|
2006-01-08 00:38:15 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'check that cherry with limit returns only the top patch'\
|
2007-07-03 05:52:14 +00:00
|
|
|
'expr "$(echo $(git cherry master my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
|
2006-01-08 00:38:15 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' \
|
2007-07-03 05:52:14 +00:00
|
|
|
'git cherry-pick my-topic-branch^0 &&
|
|
|
|
echo $(git cherry master my-topic-branch) &&
|
|
|
|
expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
|
2006-01-08 00:38:15 +00:00
|
|
|
'
|
|
|
|
|
2020-08-18 22:08:54 +00:00
|
|
|
test_expect_success 'cherry ignores whitespace' '
|
|
|
|
git switch --orphan=upstream-with-space &&
|
|
|
|
test_commit initial file &&
|
|
|
|
>expect &&
|
|
|
|
git switch --create=feature-without-space &&
|
|
|
|
|
|
|
|
# A spaceless file on the feature branch. Expect a match upstream.
|
|
|
|
printf space >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m"file without space" &&
|
|
|
|
git log --format="- %H" -1 >>expect &&
|
|
|
|
|
|
|
|
# A further change. Should not match upstream.
|
|
|
|
test_commit change file &&
|
|
|
|
git log --format="+ %H" -1 >>expect &&
|
|
|
|
|
|
|
|
git switch upstream-with-space &&
|
|
|
|
# Same as the spaceless file, just with spaces and on upstream.
|
|
|
|
test_commit "file with space" file "s p a c e" file-with-space &&
|
|
|
|
git cherry upstream-with-space feature-without-space >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2006-01-08 00:38:15 +00:00
|
|
|
test_done
|