| 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 main branch, and |
| 9 | checks that git cherry only returns the second patch in the local branch |
| 10 | ' |
| 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 13 | |
| 14 | . ./test-lib.sh |
| 15 | |
| 16 | GIT_AUTHOR_EMAIL=bogus_email_address |
| 17 | export GIT_AUTHOR_EMAIL |
| 18 | |
| 19 | test_expect_success 'prepare repository with topic branch, and check cherry finds the 2 patches from there' ' |
| 20 | echo First > A && |
| 21 | git update-index --add A && |
| 22 | test_tick && |
| 23 | git commit -m "Add A." && |
| 24 | |
| 25 | git checkout -b my-topic-branch && |
| 26 | |
| 27 | echo Second > B && |
| 28 | git update-index --add B && |
| 29 | test_tick && |
| 30 | git commit -m "Add B." && |
| 31 | |
| 32 | echo AnotherSecond > C && |
| 33 | git update-index --add C && |
| 34 | test_tick && |
| 35 | git commit -m "Add C." && |
| 36 | |
| 37 | git checkout -f main && |
| 38 | rm -f B C && |
| 39 | |
| 40 | echo Third >> A && |
| 41 | git update-index A && |
| 42 | test_tick && |
| 43 | git commit -m "Modify A." && |
| 44 | |
| 45 | expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* + .*" |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'check that cherry with limit returns only the top patch' ' |
| 49 | expr "$(echo $(git cherry main my-topic-branch my-topic-branch^1) )" : "+ [^ ]*" |
| 50 | ' |
| 51 | |
| 52 | test_expect_success '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 main my-topic-branch) && |
| 55 | expr "$(echo $(git cherry main 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 | # Reuse the expect file from the previous test, in a partial clone |
| 82 | test_expect_success 'cherry in partial clone does bulk prefetch' ' |
| 83 | test_config uploadpack.allowfilter 1 && |
| 84 | test_config uploadpack.allowanysha1inwant 1 && |
| 85 | test_when_finished "rm -rf copy" && |
| 86 | |
| 87 | git clone --bare --filter=blob:none file://"$(pwd)" copy && |
| 88 | ( |
| 89 | cd copy && |
| 90 | GIT_TRACE2_EVENT="$(pwd)/trace.output" git cherry upstream-with-space feature-without-space >actual && |
| 91 | test_cmp ../expect actual && |
| 92 | |
| 93 | grep "child_start.*fetch.negotiationAlgorithm" trace.output >fetches && |
| 94 | test_line_count = 1 fetches && |
| 95 | test_trace2_data promisor fetch_count 4 <trace.output && |
| 96 | |
| 97 | # A second invocation should not refetch any blobs, since |
| 98 | # the prefetch is expected to filter out OIDs that are |
| 99 | # already present locally. |
| 100 | GIT_TRACE2_EVENT="$(pwd)/trace2.output" git cherry upstream-with-space feature-without-space >actual && |
| 101 | test_cmp ../expect actual && |
| 102 | |
| 103 | ! grep "child_start.*fetch.negotiationAlgorithm" trace2.output && |
| 104 | ! grep "\"key\":\"fetch_count\"" trace2.output |
| 105 | ) |
| 106 | ' |
| 107 | |
| 108 | test_done |