{"thread":{"id":"31989","subject":"Re: pre-receive hook output invalid characters","startedAt":"2012-10-31T16:27:18Z","lastAt":"2012-11-01T00:54:16Z","messageCount":3,"participants":["Erik Faye-Lund","mnaoumov@gmail.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"202330","messageId":"CABPQNSZqNyKvFKoG6E0+JDaaNnUbWCaFH-WfKE1MicwDH-3TFA@mail.gmail.com","threadId":"31989","inReplyTo":"CABPQNSYj1-aaQieztkLxZjOhBQMqBJy+9POcmMcjGO4-a=EM9Q@mail.gmail.com","subject":"Re: pre-receive hook output invalid characters","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-10-31T16:27:18Z","receivedAt":"2012-10-31T16:27:18Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Wed, Oct 31, 2012 at 4:45 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:\n\n> On Wed, Oct 31, 2012 at 4:24 PM, <mnaoumov@gmail.com> wrote:\n>\n>> If you add *pre-receive* hook in your git repository with the following\n>> content\n>>\n>> #!/bin/sh\n>>\n>> echo Message\n>> exit 1\n>>\n>> And then try to push you will get the following\n>>\n>> [image: Git Extensions push]<https://a248.e.akamai.net/camo.github.com/04b160d6fd381c09c7b0a9f30400e981a086fd46/687474703a2f2f692e696d6775722e636f6d2f4431714b722e706e67>\n>>\n>> The bug is about these strange 3 last characters.\n>>\n>> Recently I raised a bug for GitExtensions but it seems to be msysgit\n>> issue as I could reproduce it from PowerShell as well\n>>\n>> https://github.com/gitextensions/gitextensions/issues/1313\n>>\n>>\n\n\n> What you're seeing is most likely a CR (a carriage return character).\n> Windows has CRLF new-lines, and Unix uses only LF.\n>\n> My guess is that echo produces CRLF, and this gets carried through and\n> incorrecly displayed.\n>\n\nOK, I can reproduce it in Git Bash now, and by doing \"git push 2>&1 | od\n-c\" I can see that I'm getting \"Message\\033[K\\n\".\n\nThis looks a little bit puzzling, but the sequence matches ANSI_SUFFIX in\nsideband.c. So it seems this is intentional. This dates back to ebe8fa73.\n\nI wonder, shouldn't we check isatty also before assuming ANSI-sequences?\n\n---8<---\ndiff --git a/sideband.c b/sideband.c\nindex d5ffa1c..bd3e5a8 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -29,7 +29,7 @@ int recv_sideband(const char *me, int in_stream, int out)\n\n  memcpy(buf, PREFIX, pf);\n  term = getenv(\"TERM\");\n- if (term && strcmp(term, \"dumb\"))\n+ if (isatty(out) && term && strcmp(term, \"dumb\"))\n  suffix = ANSI_SUFFIX;\n  else\n  suffix = DUMB_SUFFIX;\n---8<---\n\nThoughts?\n\nUnfortunately, I cannot reproduce it; all my attempts on using a local\n> pre-receive hook seems to cause the following error:\n>\n> \"error: cannot spawn hooks/pre-receive: No such file or directory\"\n>\n> I have no clue why.\n>\n\nOK, that just me being stupid.\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"202331","messageId":"CABPQNSb0pWAwwrZ5LvOY2agdEa+MXPMvg+kFa1vODhXf6efAZw@mail.gmail.com","threadId":"31989","inReplyTo":"CABPQNSZqNyKvFKoG6E0+JDaaNnUbWCaFH-WfKE1MicwDH-3TFA@mail.gmail.com","subject":"pre-receive hook output invalid characters","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-10-31T16:31:44Z","receivedAt":"2012-10-31T16:31:44Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Sorry for resending, but the previous version got dropped from the\nmain git mailing list due to a HTML-subpart. Converted to plain-text.\n\nOn Wed, Oct 31, 2012 at 4:45 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:\n>\n> On Wed, Oct 31, 2012 at 4:24 PM, <mnaoumov@gmail.com> wrote:\n>>\n>> If you add pre-receive hook in your git repository with the following\n>> content\n>>\n>> #!/bin/sh\n>>\n>> echo Message\n>> exit 1\n>>\n>> And then try to push you will get the following\n>>\n>> The bug is about these strange 3 last characters.\n>>\n>> Recently I raised a bug for GitExtensions but it seems to be msysgit\n>> issue as I could reproduce it from PowerShell as well\n>>\n>> https://github.com/gitextensions/gitextensions/issues/1313\n\n\n\n>\n> What you're seeing is most likely a CR (a carriage return character).\n> Windows has CRLF new-lines, and Unix uses only LF.\n>\n> My guess is that echo produces CRLF, and this gets carried through and\n> incorrecly displayed.\n\n\nOK, I can reproduce it in Git Bash now, and by doing \"git push 2>&1 | od -c\"\nI can see that I'm getting \"Message\\033[K\\n\".\n\nThis looks a little bit puzzling, but the sequence matches ANSI_SUFFIX in\nsideband.c. So it seems this is intentional. This dates back to ebe8fa73.\n\nI wonder, shouldn't we check isatty also before assuming ANSI-sequences?\n\n---8<---\ndiff --git a/sideband.c b/sideband.c\nindex d5ffa1c..bd3e5a8 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -29,7 +29,7 @@ int recv_sideband(const char *me, int in_stream, int out)\n\n  memcpy(buf, PREFIX, pf);\n  term = getenv(\"TERM\");\n- if (term && strcmp(term, \"dumb\"))\n+ if (isatty(out) && term && strcmp(term, \"dumb\"))\n  suffix = ANSI_SUFFIX;\n  else\n  suffix = DUMB_SUFFIX;\n---8<---\n\nThoughts?\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"202358","messageId":"b7f0b4cb-cf31-4abb-8682-5d43acaafbbf@googlegroups.com","threadId":"31989","inReplyTo":"CABPQNSb0pWAwwrZ5LvOY2agdEa+MXPMvg+kFa1vODhXf6efAZw@mail.gmail.com","subject":"Re: pre-receive hook output invalid characters","fromName":"","fromEmail":"mnaoumov@gmail.com","sentAt":"2012-11-01T00:54:16Z","receivedAt":"2012-11-01T00:54:16Z","isPatch":false,"sender":{"key":"mnaoumov@gmail.com","avatar":null},"body":"Your suggestion seems to be logical for me :)\n\nOn Thursday, November 1, 2012 3:32:26 AM UTC+11, Erik Faye-Lund wrote:\n>\n> Sorry for resending, but the previous version got dropped from the \n> main git mailing list due to a HTML-subpart. Converted to plain-text. \n>\n> On Wed, Oct 31, 2012 at 4:45 PM, Erik Faye-Lund <kusm...@gmail.com<javascript:>> \n> wrote: \n> > \n> > On Wed, Oct 31, 2012 at 4:24 PM, <mnao...@gmail.com <javascript:>> \n> wrote: \n> >> \n> >> If you add pre-receive hook in your git repository with the following \n> >> content \n> >> \n> >> #!/bin/sh \n> >> \n> >> echo Message \n> >> exit 1 \n> >> \n> >> And then try to push you will get the following \n> >> \n> >> The bug is about these strange 3 last characters. \n> >> \n> >> Recently I raised a bug for GitExtensions but it seems to be msysgit \n> >> issue as I could reproduce it from PowerShell as well \n> >> \n> >> https://github.com/gitextensions/gitextensions/issues/1313 \n>\n>\n>\n> > \n> > What you're seeing is most likely a CR (a carriage return character). \n> > Windows has CRLF new-lines, and Unix uses only LF. \n> > \n> > My guess is that echo produces CRLF, and this gets carried through and \n> > incorrecly displayed. \n>\n>\n> OK, I can reproduce it in Git Bash now, and by doing \"git push 2>&1 | od \n> -c\" \n> I can see that I'm getting \"Message\\033[K\\n\". \n>\n> This looks a little bit puzzling, but the sequence matches ANSI_SUFFIX in \n> sideband.c. So it seems this is intentional. This dates back to ebe8fa73. \n>\n> I wonder, shouldn't we check isatty also before assuming ANSI-sequences? \n>\n> ---8<--- \n> diff --git a/sideband.c b/sideband.c \n> index d5ffa1c..bd3e5a8 100644 \n> --- a/sideband.c \n> +++ b/sideband.c \n> @@ -29,7 +29,7 @@ int recv_sideband(const char *me, int in_stream, int \n> out) \n>\n>   memcpy(buf, PREFIX, pf); \n>   term = getenv(\"TERM\"); \n> - if (term && strcmp(term, \"dumb\")) \n> + if (isatty(out) && term && strcmp(term, \"dumb\")) \n>   suffix = ANSI_SUFFIX; \n>   else \n>   suffix = DUMB_SUFFIX; \n> ---8<--- \n>\n> Thoughts? \n>\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"}]}