{"thread":{"id":"17109","subject":"[PATCH] git-am: add --directory=<dir> option","startedAt":"2009-01-12T06:33:56Z","lastAt":"2009-01-15T01:08:56Z","messageCount":4,"participants":["Junio C Hamano","Stephan Beyer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"100077","messageId":"7vbpudjanf.fsf@gitster.siamese.dyndns.org","threadId":"17109","inReplyTo":null,"subject":"[PATCH] git-am: add --directory=<dir> option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-12T06:33:56Z","receivedAt":"2009-01-12T06:33:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks to a200337 (git-am: propagate -C<n>, -p<n> options as well,\n2008-12-04) and commits around it, \"git am\" is equipped to correctly\npropagate the command line flags such as -C/-p/-whitespace across a patch\nfailure and restart.\n\nIt is trivial to support --directory option now, resurrecting previous\nattempts by Kevin and Simon.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n \"What's cooking\" has listed kb/am-directory in \"Stalled\" category for too\n long a time and I dropped it entirely.  This resurrects the feature.\n\n git-am.sh             |   17 +++++++++++++----\n t/t4252-am-options.sh |    8 ++++++++\n 2 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git c/git-am.sh w/git-am.sh\nindex 4b157fe..7e6329b 100755\n--- c/git-am.sh\n+++ w/git-am.sh\n@@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit message\n u,utf8          recode into utf8 (default)\n k,keep          pass -k flag to git-mailinfo\n whitespace=     pass it through git-apply\n+directory=      pass it through git-apply\n C=              pass it through git-apply\n p=              pass it through git-apply\n resolvemsg=     override error message when patch failure occurs\n@@ -33,6 +34,14 @@ cd_to_toplevel\n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\n \n+sq () {\n+\tfor sqarg\n+\tdo\n+\t\tprintf \"%s\" \"$sqarg\" |\n+\t\tsed -e 's/'\\''/'\\''\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n+\tdone\n+}\n+\n stop_here () {\n     echo \"$1\" >\"$dotest/next\"\n     exit 1\n@@ -155,10 +164,10 @@ do\n \t\t;;\n \t--resolvemsg)\n \t\tshift; resolvemsg=$1 ;;\n-\t--whitespace)\n-\t\tgit_apply_opt=\"$git_apply_opt $1=$2\"; shift ;;\n+\t--whitespace|--directory)\n+\t\tgit_apply_opt=\"$git_apply_opt $(sq \"$1=$2\")\"; shift ;;\n \t-C|-p)\n-\t\tgit_apply_opt=\"$git_apply_opt $1$2\"; shift ;;\n+\t\tgit_apply_opt=\"$git_apply_opt $(sq \"$1$2\")\"; shift ;;\n \t--)\n \t\tshift; break ;;\n \t*)\n@@ -459,7 +468,7 @@ do\n \n \tcase \"$resolved\" in\n \t'')\n-\t\tgit apply $git_apply_opt --index \"$dotest/patch\"\n+\t\teval 'git apply '\"$git_apply_opt\"' --index \"$dotest/patch\"'\n \t\tapply_status=$?\n \t\t;;\n \tt)\ndiff --git c/t/t4252-am-options.sh w/t/t4252-am-options.sh\nindex 3ab9e8e..e91a6da 100755\n--- c/t/t4252-am-options.sh\n+++ w/t/t4252-am-options.sh\n@@ -50,4 +50,12 @@ test_expect_success 'interrupted am -C1 -p2' '\n \tgrep \"^Three$\" file-2\n '\n \n+test_expect_success 'interrupted am --directory=\"frotz nitfol\"' '\n+\trm -rf .git/rebase-apply &&\n+\tgit reset --hard initial &&\n+\ttest_must_fail git am --directory=\"frotz nitfol\" \"$tm\"/am-test-5-? &&\n+\tgit am --skip &&\n+\tgrep One \"frotz nitfol/file-5\"\n+'\n+\n test_done\n"},{"id":"100509","messageId":"20090114234602.GD32313@leksak.fem-net","threadId":"17109","inReplyTo":"7vbpudjanf.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-am: add --directory=<dir> option","fromName":"Stephan Beyer","fromEmail":"s-beyer@gmx.net","sentAt":"2009-01-14T23:46:02Z","receivedAt":"2009-01-14T23:46:02Z","isPatch":true,"sender":{"key":"s-beyer@gmx.net","avatar":"https://avatars.githubusercontent.com/u/143889?v=4"},"body":"Hi Junio,\n\nJunio C Hamano wrote:\n>\n>  git-am.sh             |   17 +++++++++++++----\n>  t/t4252-am-options.sh |    8 ++++++++\n>  2 files changed, 21 insertions(+), 4 deletions(-)\n\nI think this is missing some\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex b9c6fac..64c8178 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -66,6 +66,7 @@ default.   You could use `--no-utf8` to override this.\n \n -C<n>::\n -p<n>::\n+--directory=<root>::\n \tThese flags are passed to the 'git-apply' (see linkgit:git-apply[1])\n \tprogram that applies\n \tthe patch.\n\nor even\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex b9c6fac..327bc3d 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -59,13 +59,10 @@ default.   You could use `--no-utf8` to override this.\n \tit is supposed to apply to, and we have those blobs\n \tavailable locally.\n \n---whitespace=<option>::\n-\tThis flag is passed to the 'git-apply' (see linkgit:git-apply[1])\n-\tprogram that applies\n-\tthe patch.\n-\n -C<n>::\n -p<n>::\n+--directory=<root>::\n+--whitespace=<option>::\n \tThese flags are passed to the 'git-apply' (see linkgit:git-apply[1])\n \tprogram that applies\n \tthe patch.\n\n> diff --git c/git-am.sh w/git-am.sh\n> index 4b157fe..7e6329b 100755\n> --- c/git-am.sh\n> +++ w/git-am.sh\n[...]\n> @@ -33,6 +34,14 @@ cd_to_toplevel\n>  git var GIT_COMMITTER_IDENT >/dev/null ||\n>  \tdie \"You need to set your committer info first\"\n>  \n> +sq () {\n> +\tfor sqarg\n> +\tdo\n> +\t\tprintf \"%s\" \"$sqarg\" |\n> +\t\tsed -e 's/'\\''/'\\''\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n                                  ^^^\n\n\t$ echo \"/fo'ba\" | sed -e 's/'\\''/'\\''\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n\t '/fo'''ba'\n\n\nDo I have a thinko or should it be this:\n\n+\t\tsed -e 's/'\\''/'\\''\\\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n\t\t                   ^^\n\t\t\t(added for escaping ' outside single quotes)\n\nleading to:\n\n\t$ echo \"/fo'ba\" | sed -e 's/'\\''/'\\''\\\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n\t '/fo'\\''ba'\n\n\nWell, I was unsure, so I've tested...\n\n\nWithout this change:\n\n\t$ ./git-am.sh --directory=\"fo'ba\" /tmp/test/*\n\tApplying: abcdefg\n\t./git-am.sh: eval: line 471: unexpected EOF while looking for matching\n\t`''\n\t./git-am.sh: eval: line 472: syntax error: unexpected end of file\n\tPatch failed at 0001.\n\tWhen you have resolved this problem run \"git am --resolved\".\n\tIf you would prefer to skip this patch, instead run \"git am --skip\".\n\tTo restore the original branch and stop patching run \"git am --abort\".\n\nAnd with this change:\n\n\t$ ./git-am.sh --directory=\"fo'ba\" /tmp/test/*\n\tApplying: abcdefg\n\tApplying: asdgasfh\n\n> diff --git c/t/t4252-am-options.sh w/t/t4252-am-options.sh\n> index 3ab9e8e..e91a6da 100755\n> --- c/t/t4252-am-options.sh\n> +++ w/t/t4252-am-options.sh\n> @@ -50,4 +50,12 @@ test_expect_success 'interrupted am -C1 -p2' '\n>  \tgrep \"^Three$\" file-2\n>  '\n>  \n> +test_expect_success 'interrupted am --directory=\"frotz nitfol\"' '\n> +\trm -rf .git/rebase-apply &&\n> +\tgit reset --hard initial &&\n> +\ttest_must_fail git am --directory=\"frotz nitfol\" \"$tm\"/am-test-5-? &&\n\nHave you forgotten to add the files prefixed with \"am-test-5-\" or is this\npatch based on another one?\n\n$ git ls-files t/t4252\nt/t4252/am-test-1-1\nt/t4252/am-test-1-2\nt/t4252/am-test-2-1\nt/t4252/am-test-2-2\nt/t4252/am-test-3-1\nt/t4252/am-test-3-2\nt/t4252/am-test-4-1\nt/t4252/am-test-4-2\nt/t4252/file-1-0\nt/t4252/file-2-0\n\n\nThanks and regards,\n  Stephan\n\n--------------- proposed interdiff without am-test-5* ---------------\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex b9c6fac..327bc3d 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -59,13 +59,10 @@ default.   You could use `--no-utf8` to override this.\n \tit is supposed to apply to, and we have those blobs\n \tavailable locally.\n \n---whitespace=<option>::\n-\tThis flag is passed to the 'git-apply' (see linkgit:git-apply[1])\n-\tprogram that applies\n-\tthe patch.\n-\n -C<n>::\n -p<n>::\n+--directory=<root>::\n+--whitespace=<option>::\n \tThese flags are passed to the 'git-apply' (see linkgit:git-apply[1])\n \tprogram that applies\n \tthe patch.\ndiff --git a/git-am.sh b/git-am.sh\nindex 7e6329b..ca3dbcd 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -38,7 +38,7 @@ sq () {\n \tfor sqarg\n \tdo\n \t\tprintf \"%s\" \"$sqarg\" |\n-\t\tsed -e 's/'\\''/'\\''\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n+\t\tsed -e 's/'\\''/'\\''\\\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n \tdone\n }\n \n-- \nStephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F\n"},{"id":"100515","messageId":"7vzlhtxvu5.fsf@gitster.siamese.dyndns.org","threadId":"17109","inReplyTo":"20090114234602.GD32313@leksak.fem-net","subject":"Re: [PATCH] git-am: add --directory=<dir> option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-15T00:21:38Z","receivedAt":"2009-01-15T00:21:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephan Beyer <s-beyer@gmx.net> writes:\n\n> Do I have a thinko or should it be this:\n>\n> +\t\tsed -e 's/'\\''/'\\''\\\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n> \t\t                   ^^\n> \t\t\t(added for escaping ' outside single quotes)\n\nAlmost.\n\nCertainly my original was bad; shell unquotes to \"s/'/'\\''/g\", but that\nbackslash is not protected from further interpretation by sed, which\nhappily turns backslash-single quote into a single quote, which I forgot.\n\nYou feed \"s/'/'\\\\\\''/g\" which correctly protects one backslash from sed by\ndoubling it, but it has one unnecessary extra backslash.  The extra one\ndoes not hurt because the backslash + single quote is eaten by sed to\nproduce a single quote, but it is not quite right.\n\nWe should be feeding sed with \"s/'/'\\\\''/g\", so you need to add one\nbackslash to mine.\n\n> Have you forgotten to add the files prefixed with \"am-test-5-\" or is this\n> patch based on another one?\n\nThe one I actually queued is b47dfe9 (git-am: add --directory=<dir>\noption, 2009-01-11) and it does include these test vectors.  My bad.\n\nThis patch is relative to b47dfe9.\n\n-- >8 --\nFix git-am shell quoting\n\nNoticed by Stephan Beyer; the new test is mine.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-am.sh             |    2 +-\n t/t4252-am-options.sh |    8 ++++++++\n 2 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git c/git-am.sh w/git-am.sh\nindex 7e6329b..4beb12d 100755\n--- c/git-am.sh\n+++ w/git-am.sh\n@@ -38,7 +38,7 @@ sq () {\n \tfor sqarg\n \tdo\n \t\tprintf \"%s\" \"$sqarg\" |\n-\t\tsed -e 's/'\\''/'\\''\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n+\t\tsed -e 's/'\\''/'\\''\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n \tdone\n }\n \ndiff --git c/t/t4252-am-options.sh w/t/t4252-am-options.sh\nindex e91a6da..5fdd188 100755\n--- c/t/t4252-am-options.sh\n+++ w/t/t4252-am-options.sh\n@@ -58,4 +58,12 @@ test_expect_success 'interrupted am --directory=\"frotz nitfol\"' '\n \tgrep One \"frotz nitfol/file-5\"\n '\n \n+test_expect_success 'apply to a funny path' '\n+\twith_sq=\"with'\\''sq\"\n+\trm -fr .git/rebase-apply &&\n+\tgit reset --hard initial &&\n+\tgit am --directory=\"$with_sq\" \"$tm\"/am-test-5-2 &&\n+\ttest -f \"$with_sq/file-5\"\n+'\n+\n test_done\n"},{"id":"100528","messageId":"20090115010856.GF32313@leksak.fem-net","threadId":"17109","inReplyTo":"7vzlhtxvu5.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-am: add --directory=<dir> option","fromName":"Stephan Beyer","fromEmail":"s-beyer@gmx.net","sentAt":"2009-01-15T01:08:56Z","receivedAt":"2009-01-15T01:08:56Z","isPatch":true,"sender":{"key":"s-beyer@gmx.net","avatar":"https://avatars.githubusercontent.com/u/143889?v=4"},"body":"Hi,\n\nJunio C Hamano wrote:\n> > Do I have a thinko or should it be this:\n> >\n> > +\t\tsed -e 's/'\\''/'\\''\\\\\\'\\'''\\''/g' -e 's/.*/ '\\''&'\\''/'\n> > \t\t                   ^^\n> > \t\t\t(added for escaping ' outside single quotes)\n> \n> Almost.\n> \n> Certainly my original was bad; shell unquotes to \"s/'/'\\''/g\", but that\n> backslash is not protected from further interpretation by sed, which\n> happily turns backslash-single quote into a single quote, which I forgot.\n> \n> You feed \"s/'/'\\\\\\''/g\" which correctly protects one backslash from sed by\n> doubling it, but it has one unnecessary extra backslash.\n\nMy attempt was to escape one backslash and to escape one single quote.\n\n> The extra one\n> does not hurt because the backslash + single quote is eaten by sed to\n> produce a single quote, but it is not quite right.\n\nWell, this explains why my syntax highlighting has \"gone mad\" in your\nformer and in my version.\n\n> We should be feeding sed with \"s/'/'\\\\''/g\", so you need to add one\n> backslash to mine.\n\nOk, works like a charm :-)\n\n> > Have you forgotten to add the files prefixed with \"am-test-5-\" or is this\n> > patch based on another one?\n> \n> The one I actually queued is b47dfe9 (git-am: add --directory=<dir>\n> option, 2009-01-11) and it does include these test vectors.  My bad.\n\nOhh, I did not even notice that you queued it, because I do not track \"next\".\n\nAnd in my git-am.txt snippet I even forgot adding the option to the synopsis.\nOh, boy. :-)\n\nI think it's fine now. :-)\n\nRegards,\n  Stephan\n\n-- \nStephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F\n"}]}