{"thread":{"id":"46093","subject":"git-send-email no longer works outside a repository?","startedAt":"2017-06-01T22:45:31Z","lastAt":"2017-06-02T01:59:38Z","messageCount":7,"participants":["Jacob Keller","Brandon Williams","Junio C Hamano","Jonathan Tan","Todd Zullinger"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"321350","messageId":"CA+P7+xr39qk9qHE0=uU3HZE2wOhU9X7rmENoDfP=bp09j9N9Mg@mail.gmail.com","threadId":"46093","inReplyTo":null,"subject":"git-send-email no longer works outside a repository?","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-06-01T22:45:04Z","receivedAt":"2017-06-01T22:45:31Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"I often use git-send-email in order to send patch files. Recently when\nI tried to do this outside a repository I got some cryptic failures,\nI'm using the master branch, git version 2.13.0.311.g0339965c70d6\n\nI generate the patch files and copy them into a separate folder\noutside of the repository, and make sure everything looks good and\nwrite a cover letter, then I try to send them with\n\n$git send-email --to=<address> 00*\nCan't call method \"repo_path\" on an undefined value at\n/home/jekeller/libexec/git-core/git-send-email line 1759.\n\nEven weirder, if I move into the repository and try to send files\nwhich are outside, such as:\n\n$git send-email --to=iwl<address> ../patches/00*\nfatal: /home/jekeller/git/patches/00*:\n'/home/jekeller/git/patches/00*' is outside repository\nformat-patch -o /tmp/AZatqXB1uD /home/jekeller/git/patches/00*:\ncommand returned error: 128\n\nI would expect that if you're outside a repository the command (as\nbefore) would alllow you to send files. It shouldn't strictly need to\nbe inside a repository to function.\n\nI found this first on pu, but as above, I checked out master and still\nseem to have the problem.\n\nI'm working on a bisect now.\n\nThanks,\nJake\n"},{"id":"321351","messageId":"20170601230002.GB159608@google.com","threadId":"46093","inReplyTo":"CA+P7+xr39qk9qHE0=uU3HZE2wOhU9X7rmENoDfP=bp09j9N9Mg@mail.gmail.com","subject":"Re: git-send-email no longer works outside a repository?","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-01T23:00:02Z","receivedAt":"2017-06-01T23:00:11Z","isPatch":false,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 06/01, Jacob Keller wrote:\n> I often use git-send-email in order to send patch files. Recently when\n> I tried to do this outside a repository I got some cryptic failures,\n> I'm using the master branch, git version 2.13.0.311.g0339965c70d6\n> \n> I generate the patch files and copy them into a separate folder\n> outside of the repository, and make sure everything looks good and\n> write a cover letter, then I try to send them with\n> \n> $git send-email --to=<address> 00*\n> Can't call method \"repo_path\" on an undefined value at\n> /home/jekeller/libexec/git-core/git-send-email line 1759.\n> \n> Even weirder, if I move into the repository and try to send files\n> which are outside, such as:\n> \n> $git send-email --to=iwl<address> ../patches/00*\n> fatal: /home/jekeller/git/patches/00*:\n> '/home/jekeller/git/patches/00*' is outside repository\n> format-patch -o /tmp/AZatqXB1uD /home/jekeller/git/patches/00*:\n> command returned error: 128\n> \n> I would expect that if you're outside a repository the command (as\n> before) would alllow you to send files. It shouldn't strictly need to\n> be inside a repository to function.\n> \n> I found this first on pu, but as above, I checked out master and still\n> seem to have the problem.\n> \n> I'm working on a bisect now.\n> \n> Thanks,\n> Jake\n\nThis looks like it is due to '6489660b4\n(origin/jt/send-email-validate-hook) send-email: support validate hook'.\nIt's trying to look for a hook in a non-existent repository.\n\n-- \nBrandon Williams\n"},{"id":"321352","messageId":"xmqqo9u747xl.fsf@gitster.mtv.corp.google.com","threadId":"46093","inReplyTo":"CA+P7+xr39qk9qHE0=uU3HZE2wOhU9X7rmENoDfP=bp09j9N9Mg@mail.gmail.com","subject":"Re: git-send-email no longer works outside a repository?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-06-01T23:14:30Z","receivedAt":"2017-06-01T23:14:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> I often use git-send-email in order to send patch files. Recently when\n> I tried to do this outside a repository I got some cryptic failures,\n> I'm using the master branch, git version 2.13.0.311.g0339965c70d6\n>\n> I generate the patch files and copy them into a separate folder\n> outside of the repository, and make sure everything looks good and\n> write a cover letter, then I try to send them with\n>\n> $git send-email --to=<address> 00*\n> Can't call method \"repo_path\" on an undefined value at\n> /home/jekeller/libexec/git-core/git-send-email line 1759.\n>\n> Even weirder, if I move into the repository and try to send files\n> which are outside, such as:\n>\n> $git send-email --to=iwl<address> ../patches/00*\n> fatal: /home/jekeller/git/patches/00*:\n> '/home/jekeller/git/patches/00*' is outside repository\n> format-patch -o /tmp/AZatqXB1uD /home/jekeller/git/patches/00*:\n> command returned error: 128\n>\n> I would expect that if you're outside a repository the command (as\n> before) would alllow you to send files. It shouldn't strictly need to\n> be inside a repository to function.\n>\n> I found this first on pu, but as above, I checked out master and still\n> seem to have the problem.\n>\n> I'm working on a bisect now.\n\nThis certainly is not an intended change.  That validate-hook thing\nmust be made optional and conditional to the existence of a\nrepository.\n\nThanks for reporting.\n"},{"id":"321358","messageId":"20170601235055.22621-1-jonathantanmy@google.com","threadId":"46093","inReplyTo":"CA+P7+xr39qk9qHE0=uU3HZE2wOhU9X7rmENoDfP=bp09j9N9Mg@mail.gmail.com","subject":"[PATCH] send-email: check for repo before invoking hook","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2017-06-01T23:50:55Z","receivedAt":"2017-06-01T23:51:25Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Unless --no-validate is passed, send-email will invoke\n$repo->repo_path() in its search for a validate hook regardless of\nwhether a Git repo is actually present.  Teach send-email to first check\nfor repo existence.\n\nSigned-off-by: Jonathan Tan <jonathantanmy@google.com>\n---\nThanks for the notification. Here's a patch to fix that.\n---\n git-send-email.perl   | 32 +++++++++++++++++---------------\n t/t9001-send-email.sh |  8 ++++++++\n 2 files changed, 25 insertions(+), 15 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex f0417f64e..94c54dc5a 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1755,21 +1755,23 @@ sub unique_email_list {\n sub validate_patch {\n \tmy $fn = shift;\n \n-\tmy $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),\n-\t\t\t\t    'sendemail-validate');\n-\tmy $hook_error;\n-\tif (-x $validate_hook) {\n-\t\tmy $target = abs_path($fn);\n-\t\t# The hook needs a correct cwd and GIT_DIR.\n-\t\tmy $cwd_save = cwd();\n-\t\tchdir($repo->wc_path() or $repo->repo_path())\n-\t\t\tor die(\"chdir: $!\");\n-\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path();\n-\t\t$hook_error = \"rejected by sendemail-validate hook\"\n-\t\t\tif system($validate_hook, $target);\n-\t\tchdir($cwd_save) or die(\"chdir: $!\");\n-\t}\n-\treturn $hook_error if $hook_error;\n+\tif ($repo) {\n+\t\tmy $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),\n+\t\t\t\t\t    'sendemail-validate');\n+\t\tmy $hook_error;\n+\t\tif (-x $validate_hook) {\n+\t\t\tmy $target = abs_path($fn);\n+\t\t\t# The hook needs a correct cwd and GIT_DIR.\n+\t\t\tmy $cwd_save = cwd();\n+\t\t\tchdir($repo->wc_path() or $repo->repo_path())\n+\t\t\t\tor die(\"chdir: $!\");\n+\t\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path();\n+\t\t\t$hook_error = \"rejected by sendemail-validate hook\"\n+\t\t\t\tif system($validate_hook, $target);\n+\t\t\tchdir($cwd_save) or die(\"chdir: $!\");\n+\t\t}\n+\t\treturn $hook_error if $hook_error;\n+\t}\n \n \topen(my $fh, '<', $fn)\n \t\tor die sprintf(__(\"unable to open %s: %s\\n\"), $fn, $!);\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 15128c755..d1e4e8ad1 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -1953,4 +1953,12 @@ test_expect_success $PREREQ 'invoke hook' '\n \t)\n '\n \n+test_expect_success $PREREQ 'test that send-email works outside a repo' '\n+\tnongit git send-email \\\n+\t\t--from=\"Example <nobody@example.com>\" \\\n+\t\t--to=nobody@example.com \\\n+\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\t\"$(pwd)/0001-add-master.patch\"\n+'\n+\n test_done\n-- \n2.13.0.506.g27d5fe0cd-goog\n\n"},{"id":"321363","messageId":"20170602002249.GI25542@zaya.teonanacatl.net","threadId":"46093","inReplyTo":"20170601235055.22621-1-jonathantanmy@google.com","subject":"Re: [PATCH] send-email: check for repo before invoking hook","fromName":"Todd Zullinger","fromEmail":"tmz@pobox.com","sentAt":"2017-06-02T00:22:49Z","receivedAt":"2017-06-02T00:22:59Z","isPatch":true,"sender":{"key":"tmz@pobox.com","avatar":"https://avatars.githubusercontent.com/u/806319?v=4"},"body":"Hi Jonathan,\n\nJonathan Tan wrote:\n> Thanks for the notification. Here's a patch to fix that. \n> --- \n> git-send-email.perl   | 32 +++++++++++++++++--------------- \n> t/t9001-send-email.sh |  8 ++++++++ \n> 2 files changed, 25 insertions(+), 15 deletions(-)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl \n> index f0417f64e..94c54dc5a 100755 \n> --- a/git-send-email.perl \n> +++ b/git-send-email.perl \n> @@ -1755,21 +1755,23 @@ sub unique_email_list { \n> sub validate_patch { \n> \tmy $fn = shift;\n>\n> -\tmy $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), \n> -\t\t\t\t    'sendemail-validate'); \n> -\tmy $hook_error; \n> -\tif (-x $validate_hook) { \n> -\t\tmy $target = abs_path($fn); \n> -\t\t# The hook needs a correct cwd and GIT_DIR. \n> -\t\tmy $cwd_save = cwd(); \n> -\t\tchdir($repo->wc_path() or $repo->repo_path()) \n> -\t\t\tor die(\"chdir: $!\"); \n> -\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path(); \n> -\t\t$hook_error = \"rejected by sendemail-validate hook\" \n> -\t\t\tif system($validate_hook, $target); \n> -\t\tchdir($cwd_save) or die(\"chdir: $!\"); \n> -\t} \n> -\treturn $hook_error if $hook_error; \n> +\tif ($repo) { \n> +\t\tmy $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), \n> +\t\t\t\t\t    'sendemail-validate'); \n> +\t\tmy $hook_error; \n> +\t\tif (-x $validate_hook) { \n> +\t\t\tmy $target = abs_path($fn); \n> +\t\t\t# The hook needs a correct cwd and GIT_DIR. \n> +\t\t\tmy $cwd_save = cwd(); \n> +\t\t\tchdir($repo->wc_path() or $repo->repo_path()) \n> +\t\t\t\tor die(\"chdir: $!\"); \n> +\t\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path(); \n> +\t\t\t$hook_error = \"rejected by sendemail-validate hook\" \n> +\t\t\t\tif system($validate_hook, $target); \n> +\t\t\tchdir($cwd_save) or die(\"chdir: $!\"); \n> +\t\t} \n> +\t\treturn $hook_error if $hook_error; \n> +\t}\n\nWould it be worth doing the $repo test when defining $validate_hook \nto avoid a layer of indentation?  Something like this (with whatever \nproper wrapping/indentation is used for perl, if I have that wildly \nincorrect, of course)?\n\n-- >8 --\ndiff --git i/git-send-email.perl w/git-send-email.perl\nindex f0417f64e7..e78a0a728a 100755\n--- i/git-send-email.perl\n+++ w/git-send-email.perl\n@@ -1755,8 +1755,9 @@ sub unique_email_list {\n sub validate_patch {\n \tmy $fn = shift;\n \n-\tmy $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),\n-\t\t\t\t    'sendemail-validate');\n+\tmy $validate_hook = $repo ?\n+\t\tcatfile(catdir($repo->repo_path(), 'hooks'),\n+\t\t\t'sendemail-validate') : '';\n \tmy $hook_error;\n \tif (-x $validate_hook) {\n \t\tmy $target = abs_path($fn);\n\n-- \nTodd\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nI have to decide between two equally frightening options.  If I wanted\nto do that, I'd vote.\n    -- Duckman\n\n"},{"id":"321368","messageId":"CA+P7+xrb-a_UczPkdPSgZN7jW0zBU6v8yJ7Q20maNAROzyKBzA@mail.gmail.com","threadId":"46093","inReplyTo":"20170602002249.GI25542@zaya.teonanacatl.net","subject":"Re: [PATCH] send-email: check for repo before invoking hook","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-06-02T00:49:18Z","receivedAt":"2017-06-02T00:49:45Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Jun 1, 2017 at 5:22 PM, Todd Zullinger <tmz@pobox.com> wrote:\n> Hi Jonathan,\n>\n> Jonathan Tan wrote:\n>>\n>> Thanks for the notification. Here's a patch to fix that. ---\n>> git-send-email.perl   | 32 +++++++++++++++++---------------\n>> t/t9001-send-email.sh |  8 ++++++++ 2 files changed, 25 insertions(+), 15\n>> deletions(-)\n>>\n>> diff --git a/git-send-email.perl b/git-send-email.perl index\n>> f0417f64e..94c54dc5a 100755 --- a/git-send-email.perl +++\n>> b/git-send-email.perl @@ -1755,21 +1755,23 @@ sub unique_email_list { sub\n>> validate_patch {       my $fn = shift;\n>>\n>> -       my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), -\n>> 'sendemail-validate'); -    my $hook_error; -       if (-x $validate_hook) {\n>> -              my $target = abs_path($fn); -           # The hook needs a\n>> correct cwd and GIT_DIR. -           my $cwd_save = cwd(); -\n>> chdir($repo->wc_path() or $repo->repo_path()) -                 or\n>> die(\"chdir: $!\"); -          local $ENV{\"GIT_DIR\"} = $repo->repo_path(); -\n>> $hook_error = \"rejected by sendemail-validate hook\" -                   if\n>> system($validate_hook, $target); -           chdir($cwd_save) or die(\"chdir:\n>> $!\"); - } -     return $hook_error if $hook_error; +    if ($repo) { +\n>> my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), +\n>> 'sendemail-validate'); +            my $hook_error; +               if (-x\n>> $validate_hook) { +                      my $target = abs_path($fn); +\n>> # The hook needs a correct cwd and GIT_DIR. +                   my $cwd_save\n>> = cwd(); +                 chdir($repo->wc_path() or $repo->repo_path()) +\n>> or die(\"chdir: $!\"); +                  local $ENV{\"GIT_DIR\"} =\n>> $repo->repo_path(); +                   $hook_error = \"rejected by\n>> sendemail-validate hook\" +                           if\n>> system($validate_hook, $target); +                   chdir($cwd_save) or\n>> die(\"chdir: $!\"); +         } +             return $hook_error if\n>> $hook_error; +    }\n>\n>\n> Would it be worth doing the $repo test when defining $validate_hook to avoid\n> a layer of indentation?  Something like this (with whatever proper\n> wrapping/indentation is used for perl, if I have that wildly incorrect, of\n> course)?\n>\n\nThis approach makes more sense to me, but either should fix the bug.\nThe first approach might be more resilient against future changes\nthough...?\n\nThanks,\nJake\n\n> -- >8 --\n> diff --git i/git-send-email.perl w/git-send-email.perl\n> index f0417f64e7..e78a0a728a 100755\n> --- i/git-send-email.perl\n> +++ w/git-send-email.perl\n> @@ -1755,8 +1755,9 @@ sub unique_email_list {\n> sub validate_patch {\n>         my $fn = shift;\n>\n> -       my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),\n> -                                   'sendemail-validate');\n> +       my $validate_hook = $repo ?\n> +               catfile(catdir($repo->repo_path(), 'hooks'),\n> +                       'sendemail-validate') : '';\n>         my $hook_error;\n>         if (-x $validate_hook) {\n>                 my $target = abs_path($fn);\n>\n> --\n> Todd\n> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n> I have to decide between two equally frightening options.  If I wanted\n> to do that, I'd vote.\n>    -- Duckman\n>\n"},{"id":"321378","messageId":"xmqqinkf175n.fsf@gitster.mtv.corp.google.com","threadId":"46093","inReplyTo":"20170601235055.22621-1-jonathantanmy@google.com","subject":"Re: [PATCH] send-email: check for repo before invoking hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-06-02T01:59:32Z","receivedAt":"2017-06-02T01:59:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.  \n\n\"git show -w\" tells readers how this fix is trivially correct ;-)\n\nWill apply.\n"}]}