#!/bin/sh global test_description := ''Test workflows involving pull request.'' source ./test-lib.sh test_expect_success 'setup' ' git init --bare upstream.git && git init --bare downstream.git && git clone upstream.git upstream-private && git clone downstream.git local && trash_url="file://$TRASH_DIRECTORY" && downstream_url="$trash_url/downstream.git/" && upstream_url="$trash_url/upstream.git/" && ( cd upstream-private && cat <<-\EOT >mnemonic.txt && Thirtey days hath November, Aprile, June, and September: EOT git add mnemonic.txt && test_tick && git commit -m "\"Thirty days\", a reminder of month lengths" && git tag -m "version 1" -a initial && git push --tags origin master ) && ( cd local && git remote add upstream "$trash_url/upstream.git" && git fetch upstream && git pull upstream master && cat <<-\EOT >>mnemonic.txt && Of twyecescore-eightt is but eine, And all the remnante be thrycescore-eine. O’course Leap yare comes an’pynes, Ev’rie foure yares, gote it ryghth. An’twyecescore-eight is but twyecescore-nyne. EOT git add mnemonic.txt && test_tick && git commit -m "More detail" && git tag -m "version 2" -a full && git checkout -b simplify HEAD^ && mv mnemonic.txt mnemonic.standard && cat <<-\EOT >mnemonic.clarified && Thirty days has September, All the rest I can’t remember. EOT git add -N mnemonic.standard mnemonic.clarified && git commit -a -m "Adapt to use modern, simpler English But keep the old version, too, in case some people prefer it." && git checkout master ) ' test_expect_success 'setup: two scripts for reading pull requests' ' downstream_url_for_sed=$( printf "%s\n" "$downstream_url" | sed -e '''''s/\\/\\\\/g''''' -e '''''s/[[/.*^$]/\\&/g''''' ) && cat <<-\EOT >read-request.sed && #!/bin/sed -nf # Note that a request could ask for "tag $tagname" / in the git repository at:$/!d n /^$/ n s/ tag \([^ ]*\)$/ tag--\1/ s/^[ ]*\(.*\) \([^ ]*\)/please pull\ \1\ \2/p q EOT cat <<-EOT >fuzz.sed #!/bin/sed -nf s/$downstream_url_for_sed/URL/g s/$_x40/OBJECT_NAME/g s/A U Thor/AUTHOR/g s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g s/ [^ ].*/ SUBJECT/g s/ [^ ].* (DATE)/ SUBJECT (DATE)/g s|tags/full|BRANCH|g s/mnemonic.txt/FILENAME/g s/^version [0-9]/VERSION/ /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat /^AUTHOR ([0-9]*):\$/ b shortlog p b : diffstat n / [0-9]* files* changed/ { a\\ DIFFSTAT b } b diffstat : shortlog /^ [a-zA-Z]/ n /^[a-zA-Z]* ([0-9]*):\$/ n /^\$/ N /^\n[a-zA-Z]* ([0-9]*):\$/!{ a\\ SHORTLOG D } n b shortlog EOT ' test_expect_success 'pull request when forgot to push' ' rm -fr downstream.git && git init --bare downstream.git && ( cd local && git checkout initial && git merge --ff-only master && test_must_fail git request-pull initial "$downstream_url" \ 2>../err ) && grep "No match for commit .*" err && grep "Are you sure you pushed" err ' test_expect_success 'pull request after push' ' rm -fr downstream.git && git init --bare downstream.git && ( cd local && git checkout initial && git merge --ff-only master && git push origin master:for-upstream && git request-pull initial origin master:for-upstream >../request ) && sed -nf read-request.sed digest && cat digest && { read task && read repository && read branch } ../request ) && sed -nf read-request.sed digest && cat digest && { read task && read repository && read branch } expect && The following changes since commit OBJECT_NAME: SUBJECT (DATE) are available in the git repository at: URL BRANCH for you to fetch changes up to OBJECT_NAME: SUBJECT (DATE) ---------------------------------------------------------------- VERSION ---------------------------------------------------------------- SHORTLOG DIFFSTAT EOT ( cd local && git checkout initial && git merge --ff-only master && git push origin tags/full && git request-pull initial "$downstream_url" tags/full >../request ) && request.fuzzy && test_i18ncmp expect request.fuzzy && ( cd local && git request-pull initial "$downstream_url" tags/full:refs/tags/full ) >request && sed -nf fuzz.sed request.fuzzy && test_i18ncmp expect request.fuzzy && ( cd local && git request-pull initial "$downstream_url" full ) >request && grep " tags/full\$" request ' test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' ( cd local && OPTIONS_KEEPDASHDASH=Yes && export OPTIONS_KEEPDASHDASH && git checkout initial && git merge --ff-only master && git push origin master:for-upstream && git request-pull -- initial "$downstream_url" master:for-upstream >../request ) ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test workflows involving pull request.">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\n"> <"\tgit init --bare upstream.git &&\n"> <"\tgit init --bare downstream.git &&\n"> <"\tgit clone upstream.git upstream-private &&\n"> <"\tgit clone downstream.git local &&\n"> <"\n"> <"\ttrash_url=\"file://$TRASH_DIRECTORY\" &&\n"> <"\tdownstream_url=\"$trash_url/downstream.git/\" &&\n"> <"\tupstream_url=\"$trash_url/upstream.git/\" &&\n"> <"\n"> <"\t(\n"> <"\t\tcd upstream-private &&\n"> <"\t\tcat <<-\\EOT >mnemonic.txt &&\n"> <"\t\tThirtey days hath November,\n"> <"\t\tAprile, June, and September:\n"> <"\t\tEOT\n"> <"\t\tgit add mnemonic.txt &&\n"> <"\t\ttest_tick &&\n"> <"\t\tgit commit -m \"\\\"Thirty days\\\", a reminder of month lengths\" &&\n"> <"\t\tgit tag -m \"version 1\" -a initial &&\n"> <"\t\tgit push --tags origin master\n"> <"\t) &&\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit remote add upstream \"$trash_url/upstream.git\" &&\n"> <"\t\tgit fetch upstream &&\n"> <"\t\tgit pull upstream master &&\n"> <"\t\tcat <<-\\EOT >>mnemonic.txt &&\n"> <"\t\tOf twyecescore-eightt is but eine,\n"> <"\t\tAnd all the remnante be thrycescore-eine.\n"> <"\t\tO\u2019course Leap yare comes an\u2019pynes,\n"> <"\t\tEv\u2019rie foure yares, gote it ryghth.\n"> <"\t\tAn\u2019twyecescore-eight is but twyecescore-nyne.\n"> <"\t\tEOT\n"> <"\t\tgit add mnemonic.txt &&\n"> <"\t\ttest_tick &&\n"> <"\t\tgit commit -m \"More detail\" &&\n"> <"\t\tgit tag -m \"version 2\" -a full &&\n"> <"\t\tgit checkout -b simplify HEAD^ &&\n"> <"\t\tmv mnemonic.txt mnemonic.standard &&\n"> <"\t\tcat <<-\\EOT >mnemonic.clarified &&\n"> <"\t\tThirty days has September,\n"> <"\t\tAll the rest I can\u2019t remember.\n"> <"\t\tEOT\n"> <"\t\tgit add -N mnemonic.standard mnemonic.clarified &&\n"> <"\t\tgit commit -a -m \"Adapt to use modern, simpler English\n"> <"\n"> <"But keep the old version, too, in case some people prefer it.\" &&\n"> <"\t\tgit checkout master\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup: two scripts for reading pull requests">)} { (SQ <"\n"> <"\n"> <"\tdownstream_url_for_sed=$(\n"> <"\t\tprintf \"%s\\n\" \"$downstream_url\" |\n"> <"\t\tsed -e "> ) (EscapedLiteralPart token:) (SQ <"s/\\\\/\\\\\\\\/g">) (EscapedLiteralPart token:) (SQ <" -e ">) (EscapedLiteralPart token:) (SQ <"s/[[/.*^$]/\\\\&/g">) (EscapedLiteralPart token:) (SQ <"\n"> <"\t) &&\n"> <"\n"> <"\tcat <<-\\EOT >read-request.sed &&\n"> <"\t#!/bin/sed -nf\n"> <"\t# Note that a request could ask for \"tag $tagname\"\n"> <"\t/ in the git repository at:$/!d\n"> <"\tn\n"> <"\t/^$/ n\n"> <"\ts/ tag \\([^ ]*\\)$/ tag--\\1/\n"> <"\ts/^[ \t]*\\(.*\\) \\([^ ]*\\)/please pull\\\n"> <"\t\\1\\\n"> <"\t\\2/p\n"> <"\tq\n"> <"\tEOT\n"> <"\n"> <"\tcat <<-EOT >fuzz.sed\n"> <"\t#!/bin/sed -nf\n"> <"\ts/$downstream_url_for_sed/URL/g\n"> <"\ts/$_x40/OBJECT_NAME/g\n"> <"\ts/A U Thor/AUTHOR/g\n"> <"\ts/[-0-9]\\{10\\} [:0-9]\\{8\\} [-+][0-9]\\{4\\}/DATE/g\n"> <"\ts/ [^ ].*/ SUBJECT/g\n"> <"\ts/ [^ ].* (DATE)/ SUBJECT (DATE)/g\n"> <"\ts|tags/full|BRANCH|g\n"> <"\ts/mnemonic.txt/FILENAME/g\n"> <"\ts/^version [0-9]/VERSION/\n"> <"\t/^ FILENAME | *[0-9]* [-+]*\\$/ b diffstat\n"> <"\t/^AUTHOR ([0-9]*):\\$/ b shortlog\n"> <"\tp\n"> <"\tb\n"> <"\t: diffstat\n"> <"\tn\n"> <"\t/ [0-9]* files* changed/ {\n"> <"\t\ta\\\\\n"> <"\tDIFFSTAT\n"> <"\t\tb\n"> <"\t}\n"> <"\tb diffstat\n"> <"\t: shortlog\n"> <"\t/^ [a-zA-Z]/ n\n"> <"\t/^[a-zA-Z]* ([0-9]*):\\$/ n\n"> <"\t/^\\$/ N\n"> <"\t/^\\n[a-zA-Z]* ([0-9]*):\\$/!{\n"> <"\t\ta\\\\\n"> <"\tSHORTLOG\n"> <"\t\tD\n"> <"\t}\n"> <"\tn\n"> <"\tb shortlog\n"> <"\tEOT\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"pull request when forgot to push">)} { (SQ <"\n"> <"\n"> <"\trm -fr downstream.git &&\n"> <"\tgit init --bare downstream.git &&\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit merge --ff-only master &&\n"> <"\t\ttest_must_fail git request-pull initial \"$downstream_url\" \\\n"> <"\t\t\t2>../err\n"> <"\t) &&\n"> <"\tgrep \"No match for commit .*\" err &&\n"> <"\tgrep \"Are you sure you pushed\" err\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"pull request after push">)} { (SQ <"\n"> <"\n"> <"\trm -fr downstream.git &&\n"> <"\tgit init --bare downstream.git &&\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit merge --ff-only master &&\n"> <"\t\tgit push origin master:for-upstream &&\n"> <"\t\tgit request-pull initial origin master:for-upstream >../request\n"> <"\t) &&\n"> <"\tsed -nf read-request.sed digest &&\n"> <"\tcat digest &&\n"> <"\t{\n"> <"\t\tread task &&\n"> <"\t\tread repository &&\n"> <"\t\tread branch\n"> <"\t} <"\t(\n"> <"\t\tcd upstream-private &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit pull --ff-only \"$repository\" \"$branch\"\n"> <"\t) &&\n"> <"\ttest \"$branch\" = for-upstream &&\n"> <"\ttest_cmp local/mnemonic.txt upstream-private/mnemonic.txt\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"request asks HEAD to be pulled">)} { (SQ <"\n"> <"\n"> <"\trm -fr downstream.git &&\n"> <"\tgit init --bare downstream.git &&\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit merge --ff-only master &&\n"> <"\t\tgit push --tags origin master simplify &&\n"> <"\t\tgit push origin master:for-upstream &&\n"> <"\t\tgit request-pull initial \"$downstream_url\" >../request\n"> <"\t) &&\n"> <"\tsed -nf read-request.sed digest &&\n"> <"\tcat digest &&\n"> <"\t{\n"> <"\t\tread task &&\n"> <"\t\tread repository &&\n"> <"\t\tread branch\n"> <"\t} <"\ttest -z \"$branch\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"pull request format">)} { (SQ <"\n"> <"\n"> <"\trm -fr downstream.git &&\n"> <"\tgit init --bare downstream.git &&\n"> <"\tcat <<-\\EOT >expect &&\n"> <"\tThe following changes since commit OBJECT_NAME:\n"> <"\n"> <"\t SUBJECT (DATE)\n"> <"\n"> <"\tare available in the git repository at:\n"> <"\n"> <"\t URL BRANCH\n"> <"\n"> <"\tfor you to fetch changes up to OBJECT_NAME:\n"> <"\n"> <"\t SUBJECT (DATE)\n"> <"\n"> <"\t----------------------------------------------------------------\n"> <"\tVERSION\n"> <"\n"> <"\t----------------------------------------------------------------\n"> <"\tSHORTLOG\n"> <"\n"> <"\tDIFFSTAT\n"> <"\tEOT\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit merge --ff-only master &&\n"> <"\t\tgit push origin tags/full &&\n"> <"\t\tgit request-pull initial \"$downstream_url\" tags/full >../request\n"> <"\t) &&\n"> <"\trequest.fuzzy &&\n"> <"\ttest_i18ncmp expect request.fuzzy &&\n"> <"\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit request-pull initial \"$downstream_url\" tags/full:refs/tags/full\n"> <"\t) >request &&\n"> <"\tsed -nf fuzz.sed request.fuzzy &&\n"> <"\ttest_i18ncmp expect request.fuzzy &&\n"> <"\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tgit request-pull initial \"$downstream_url\" full\n"> <"\t) >request &&\n"> <"\tgrep \" tags/full\\$\" request\n"> ) } ) (C {(test_expect_success)} {(SQ <"request-pull ignores OPTIONS_KEEPDASHDASH poison">)} { (SQ <"\n"> <"\n"> <"\t(\n"> <"\t\tcd local &&\n"> <"\t\tOPTIONS_KEEPDASHDASH=Yes &&\n"> <"\t\texport OPTIONS_KEEPDASHDASH &&\n"> <"\t\tgit checkout initial &&\n"> <"\t\tgit merge --ff-only master &&\n"> <"\t\tgit push origin master:for-upstream &&\n"> <"\t\tgit request-pull -- initial \"$downstream_url\" master:for-upstream >../request\n"> <"\t)\n"> <"\n"> ) } ) (C {(test_done)}) ] )