{"thread":{"id":"27862","subject":"pre-commit not working at server side push","startedAt":"2011-07-20T06:43:56Z","lastAt":"2011-07-20T09:03:58Z","messageCount":7,"participants":["J. Bakshi","Ilari Liusvaara"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"171719","messageId":"20110720121356.4dc21f6b@shiva.selfip.org","threadId":"27862","inReplyTo":null,"subject":"pre-commit not working at server side push","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-20T06:43:56Z","receivedAt":"2011-07-20T06:43:56Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"Hello list,\n\nI have this bash script to check php syntax error and prevent the commit if there is any\n\n```````````````````\n#!/bin/sh\n\n##php_syntax_check\n\n  for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\\.(php|engine|theme|install|inc>\n        if [ -f $i ]; then\n                output=$(/usr/bin/php5 -l $i)\n                if [ \"$output\" == \"No syntax errors detected in $i\" ];\n                then\n                        echo \"PHP syntax check for $i: OK\"\n                else\n                        echo \"=====================================================================>\n                        echo \"Pause $i for the commit due to PHP parse errors:\"\n                        echo \"$output\"\n                        exit 1\n                fi\n        fi\n    done\n\n```````````````````\n\nRunning fine when placed it at local copy.\n\nI have placed the hook at the server under hooks directory and provided the execute permission also\n\n$ chmod a+x hooks/pre-commit\n\nBut even with wrong php syntax I am able to push the file. Have I missed something ?\n\nThanks\n"},{"id":"171720","messageId":"20110720124538.482628e3@shiva.selfip.org","threadId":"27862","inReplyTo":"20110720121356.4dc21f6b@shiva.selfip.org","subject":"Re: pre-commit not working at server side push","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-20T07:15:38Z","receivedAt":"2011-07-20T07:15:38Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"On Wed, 20 Jul 2011 12:13:56 +0530\n\"J. Bakshi\" <joydeep@infoservices.in> wrote:\n\n> Hello list,\n> \n> I have this bash script to check php syntax error and prevent the commit if there is any\n> \n> ```````````````````\n> #!/bin/sh\n> \n> ##php_syntax_check\n> \n>   for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\\.(php|engine|theme|install|inc>\n>         if [ -f $i ]; then\n>                 output=$(/usr/bin/php5 -l $i)\n>                 if [ \"$output\" == \"No syntax errors detected in $i\" ];\n>                 then\n>                         echo \"PHP syntax check for $i: OK\"\n>                 else\n>                         echo \"=====================================================================>\n>                         echo \"Pause $i for the commit due to PHP parse errors:\"\n>                         echo \"$output\"\n>                         exit 1\n>                 fi\n>         fi\n>     done\n> \n> ```````````````````\n> \n> Running fine when placed it at local copy.\n> \n> I have placed the hook at the server under hooks directory and provided the execute permission also\n> \n> $ chmod a+x hooks/pre-commit\n> \n> But even with wrong php syntax I am able to push the file. Have I missed something ?\n> \n> Thanks\n\nseems it should be pre-receive hook at the server. So done accordingly but still not working \n"},{"id":"171721","messageId":"20110720071807.GA10104@LK-Perkele-VI.localdomain","threadId":"27862","inReplyTo":"20110720121356.4dc21f6b@shiva.selfip.org","subject":"Re: pre-commit not working at server side push","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2011-07-20T07:18:07Z","receivedAt":"2011-07-20T07:18:07Z","isPatch":false,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Wed, Jul 20, 2011 at 12:13:56PM +0530, J. Bakshi wrote:\n> Hello list,\n> \n> I have this bash script to check php syntax error and prevent the commit if there is any\n \n<snip>\n \n> Running fine when placed it at local copy.\n> \n> I have placed the hook at the server under hooks directory and provided the execute permission also\n> \n> $ chmod a+x hooks/pre-commit\n> \n> But even with wrong php syntax I am able to push the file. Have I missed something ?\n\nPre-commit runs on commit, not on push. And push is not commit.\n\n-Ilari\n"},{"id":"171722","messageId":"20110720125124.3c746a1a@shiva.selfip.org","threadId":"27862","inReplyTo":"20110720071807.GA10104@LK-Perkele-VI.localdomain","subject":"Re: pre-commit not working at server side push","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-20T07:21:24Z","receivedAt":"2011-07-20T07:21:24Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"On Wed, 20 Jul 2011 10:18:07 +0300\nIlari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:\n\n> On Wed, Jul 20, 2011 at 12:13:56PM +0530, J. Bakshi wrote:\n> > Hello list,\n> > \n> > I have this bash script to check php syntax error and prevent the commit if there is any\n>  \n> <snip>\n>  \n> > Running fine when placed it at local copy.\n> > \n> > I have placed the hook at the server under hooks directory and provided the execute permission also\n> > \n> > $ chmod a+x hooks/pre-commit\n> > \n> > But even with wrong php syntax I am able to push the file. Have I missed something ?\n> \n> Pre-commit runs on commit, not on push. And push is not commit.\n> \n> -Ilari\n\nThanks, already figured it out, it would be pre-receive on server; but still not working.\n"},{"id":"171723","messageId":"20110720073017.GA10465@LK-Perkele-VI.localdomain","threadId":"27862","inReplyTo":"20110720124538.482628e3@shiva.selfip.org","subject":"Re: pre-commit not working at server side push","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2011-07-20T07:30:17Z","receivedAt":"2011-07-20T07:30:17Z","isPatch":false,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"On Wed, Jul 20, 2011 at 12:45:38PM +0530, J. Bakshi wrote:\n> On Wed, 20 Jul 2011 12:13:56 +0530\n> \"J. Bakshi\" <joydeep@infoservices.in> wrote:\n> \n> > Hello list,\n> > \n> > I have this bash script to check php syntax error and prevent the commit if there is any\n> > \n> > ```````````````````\n> > #!/bin/sh\n> > \n> > ##php_syntax_check\n> > \n> >   for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\\.(php|engine|theme|install|inc>\n> >         if [ -f $i ]; then\n> >                 output=$(/usr/bin/php5 -l $i)\n> >                 if [ \"$output\" == \"No syntax errors detected in $i\" ];\n> >                 then\n> >                         echo \"PHP syntax check for $i: OK\"\n> >                 else\n> >                         echo \"=====================================================================>\n> >                         echo \"Pause $i for the commit due to PHP parse errors:\"\n> >                         echo \"$output\"\n> >                         exit 1\n> >                 fi\n> >         fi\n> >     done\n> > \n> > ```````````````````\n\n> seems it should be pre-receive hook at the server. So done accordingly but still not working \n\nPre-receive runs after objects have been received but before branches are updated. So\nit can inspect the newly arrived commits but the branches retain their old values.\n\n- Firstly, the server does not have index, so diff-index does not do anything sane.\n- Secondly, HEAD does not point to anything newly arrived (the hook gets list of update \ninstructions via stdin).\n- Thirdly, this hook must be prepared for multiple commits in multiple branches appearing at\nonce.\n\nI think githooks(5) documents what these hooks receive and what they do.\n\n-Ilari\n"},{"id":"171724","messageId":"20110720131533.7bbba0c5@shiva.selfip.org","threadId":"27862","inReplyTo":"20110720073017.GA10465@LK-Perkele-VI.localdomain","subject":"Re: pre-commit not working at server side push","fromName":"J. Bakshi","fromEmail":"joydeep@infoservices.in","sentAt":"2011-07-20T07:45:33Z","receivedAt":"2011-07-20T07:45:33Z","isPatch":false,"sender":{"key":"joydeep@infoservices.in","avatar":null},"body":"On Wed, 20 Jul 2011 10:30:17 +0300\nIlari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:\n\n> On Wed, Jul 20, 2011 at 12:45:38PM +0530, J. Bakshi wrote:\n> > On Wed, 20 Jul 2011 12:13:56 +0530\n> > \"J. Bakshi\" <joydeep@infoservices.in> wrote:\n> > \n> > > Hello list,\n> > > \n> > > I have this bash script to check php syntax error and prevent the commit if there is any\n> > > \n> > > ```````````````````\n> > > #!/bin/sh\n> > > \n> > > ##php_syntax_check\n> > > \n> > >   for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\\.(php|engine|theme|install|inc>\n> > >         if [ -f $i ]; then\n> > >                 output=$(/usr/bin/php5 -l $i)\n> > >                 if [ \"$output\" == \"No syntax errors detected in $i\" ];\n> > >                 then\n> > >                         echo \"PHP syntax check for $i: OK\"\n> > >                 else\n> > >                         echo \"=====================================================================>\n> > >                         echo \"Pause $i for the commit due to PHP parse errors:\"\n> > >                         echo \"$output\"\n> > >                         exit 1\n> > >                 fi\n> > >         fi\n> > >     done\n> > > \n> > > ```````````````````\n> \n> > seems it should be pre-receive hook at the server. So done accordingly but still not working \n> \n> Pre-receive runs after objects have been received but before branches are updated. So\n> it can inspect the newly arrived commits but the branches retain their old values.\n> \n> - Firstly, the server does not have index, so diff-index does not do anything sane.\n> - Secondly, HEAD does not point to anything newly arrived (the hook gets list of update \n> instructions via stdin).\n> - Thirdly, this hook must be prepared for multiple commits in multiple branches appearing at\n> once.\n> \n> I think githooks(5) documents what these hooks receive and what they do.\n> \n> -Ilari\n\nThanks for your clarification. As a newbie I am interested to know any such pre-receive hook which can check php syntax before php.\n"},{"id":"171729","messageId":"201107200903.p6K93q7A019900@dcnode-02.unlimitedmail.net","threadId":"27862","inReplyTo":"20110720131533.7bbba0c5@shiva.selfip.org","subject":"Re: pre-commit not working at server side push","fromName":"J. Bakshi","fromEmail":"j.bakshi@unlimitedmail.org","sentAt":"2011-07-20T09:03:58Z","receivedAt":"2011-07-20T09:03:58Z","isPatch":false,"sender":{"key":"j.bakshi@unlimitedmail.org","avatar":null},"body":"On Wed, 20 Jul 2011 13:15:33 +0530\n\"J. Bakshi\" <joydeep@infoservices.in> wrote:\n\n> On Wed, 20 Jul 2011 10:30:17 +0300\n> Ilari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:\n> \n> > On Wed, Jul 20, 2011 at 12:45:38PM +0530, J. Bakshi wrote:\n> > > On Wed, 20 Jul 2011 12:13:56 +0530\n> > > \"J. Bakshi\" <joydeep@infoservices.in> wrote:\n> > > \n> > > > Hello list,\n> > > > \n> > > > I have this bash script to check php syntax error and prevent the commit if there is any\n> > > > \n> > > > ```````````````````\n> > > > #!/bin/sh\n> > > > \n> > > > ##php_syntax_check\n> > > > \n> > > >   for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\\.(php|engine|theme|install|inc>\n> > > >         if [ -f $i ]; then\n> > > >                 output=$(/usr/bin/php5 -l $i)\n> > > >                 if [ \"$output\" == \"No syntax errors detected in $i\" ];\n> > > >                 then\n> > > >                         echo \"PHP syntax check for $i: OK\"\n> > > >                 else\n> > > >                         echo \"=====================================================================>\n> > > >                         echo \"Pause $i for the commit due to PHP parse errors:\"\n> > > >                         echo \"$output\"\n> > > >                         exit 1\n> > > >                 fi\n> > > >         fi\n> > > >     done\n> > > > \n> > > > ```````````````````\n> > \n> > > seems it should be pre-receive hook at the server. So done accordingly but still not working \n> > \n> > Pre-receive runs after objects have been received but before branches are updated. So\n> > it can inspect the newly arrived commits but the branches retain their old values.\n> > \n> > - Firstly, the server does not have index, so diff-index does not do anything sane.\n> > - Secondly, HEAD does not point to anything newly arrived (the hook gets list of update \n> > instructions via stdin).\n> > - Thirdly, this hook must be prepared for multiple commits in multiple branches appearing at\n> > once.\n> > \n> > I think githooks(5) documents what these hooks receive and what they do.\n> > \n> > -Ilari\n> \n> Thanks for your clarification. As a newbie I am interested to know any such pre-receive hook which can check php syntax before php.\n\nThe script given at the link below is working fine\n\nhttp://git.661346.n2.nabble.com/Odd-results-writing-a-Git-pre-receive-hook-to-syntax-check-PHP-files-td5471120.html\n\nBut it doesn't show where the error is. The part actually checking the error is\n\n``````````\nfunction syntaxCheckFile($blob,$filename) { \n        $needle = '/(\\.php|\\.module|\\.install)$/'; \n        if (preg_match($needle,$filename)) { \n                #echo \"Checking $filename\\n\"; \n                $dummy = array(); \n                exec(\"git show $blob|/home/php/bin/php -l\",$dummy,$checkrcval); \n                if ($checkrcval != 0) { \n                        echo \"There was a syntax error in '$filename'. \n Rejecting this attempted merge!\\n\"; \n                        exit(1); \n                } \n        } \n} \n``````````\n\ncan we modify it so that it shows the error too ?\n\nPS: I am not a php guy\n"}]}