{"thread":{"id":"24891","subject":"Odd results writing a Git pre-receive hook to syntax check PHP files.","startedAt":"2010-08-27T21:07:00Z","lastAt":"2010-09-02T14:34:18Z","messageCount":20,"participants":["Chris Patti","Michael J Gruber","Jonathan Nieder","Sverre Rabbelier","Todd Zullinger","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"149144","messageId":"AANLkTikktdPoZN8MwJD+Gxus16xBGtScCAqT9W0eiWAb@mail.gmail.com","threadId":"24891","inReplyTo":null,"subject":"Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-27T21:07:00Z","receivedAt":"2010-08-27T21:07:00Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"Folks;\n\nI'm trying to write a pre-receive hook to prevent syntactically bogus\nPHP files from being 'push'ed into our master repository.\n\nIt's puzzling, my hook works *perfectly* on two different test repos,\nbut when I try to utilize it in an environment with lots of complex\nbranching, it exhibits totally (to me) unexplained behavior and fails\nutterly.\n\nHere's the correct behavior, in my test environments.  moo.php does\nindeed have a syntax error.  foo.php is syntactically correct:\n\n---\n[16:50][admin@Chris-Patti:~/src/relengtest(master)]$ git push origin master\nCounting objects: 5, done.\nDelta compression using up to 2 threads.\nCompressing objects: 100% (3/3), done.\nWriting objects: 100% (3/3), 363 bytes, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nns: d372eddeb4a6bb69576c96458040c6bf44cdee79\nos: f93a54b5bccc1630b61894f5041c0c6e105b47a3\nrefname: refs/heads/master\n\nmode: 100644 type: blob blob: 372c38001f74f92264f77d448af27d8f6225db96\nfilename: foo.php\nChecking foo.php\nmode: 100644 type: blob blob: c10ecdacc38543a880c984a478a8c62399d22e81\nfilename: moo.php\nChecking moo.php\nThere was a syntax error in 'moo.php'.  Rejecting this attempted merge!\nerror: hooks/pre-receive exited with error code 1\nTo ssh://git.bluestatedigital.com/home/git/relengtest.git\n ! [remote rejected] master -> master (pre-receive hook declined)\nerror: failed to push some refs to\n'ssh://git.bluestatedigital.com/home/git/relengtest.git'\n[16:50][admin@Chris-Patti:~/src/relengtest(master)]$\n\n---\n\nGreat, right?  I'm taking the old and new refs in, doing git ls-tree\non the new_sha1 value to get the list of all the files included in\nthis commit,a nd their blob ids, and then using git show to get the\nfiles contents and run them through the syntax checker.\n\nOnly, here's what happens when I put the identical hook into a\nrepository where I'm using a branch off a branch:\n---\n[17:01][admin@Chris-Patti:~/src/bsdrelease/test(bug-28046)]$ git push\norigin bug-28046\nCounting objects: 7, done.\nDelta compression using up to 2 threads.\nCompressing objects: 100% (4/4), done.\nWriting objects: 100% (4/4), 399 bytes, done.\nTotal 4 (delta 3), reused 0 (delta 0)\nns: d17233cfa4a7ae650a7fe0a97d336890a29a68c1\nos: ad8e2e4f9510e1fbbd3ab58a58bf218ee2aa7150\nrefname: refs/heads/bug-28046\n\nmode: 100644 type: blob blob: 9e2244625c3636978e8b44bce4ab2eb55bd100d6\nfilename: .gitignore\nmode: 100755 type: blob blob: 9c1f0855a64f5ec0be3eebb9069ab2393602d662\nfilename: bin/bsdrelease\nmode: 100755 type: blob blob: da2500c7f14cee33ab63477825390a8b7f22b74d\nfilename: bin/upgrade\nmode: 100644 type: blob blob: a93a7616245d104711261a2dcaf71ff535aac737\nfilename: lib/Horde/Argv/Parser.php\nChecking lib/Horde/Argv/Parser.php\nmode: 100644 type: blob blob: 42337c2865ee6ace45afcf11c6dfd13b10ac36c6\nfilename: lib/Horde/Controller/Dispatcher.php\nChecking lib/Horde/Controller/Dispatcher.php\nmode: 100644 type: blob blob: 59f867badec965bf03c30eb06da0eb45c85aa033\nfilename: lib/Horde/Support/Inflector.php\nChecking lib/Horde/Support/Inflector.php\nmode: 100644 type: blob blob: f36f36d22ad9fa7dc1002d5d39926046a8505d58\nfilename: lib/bootstrap.inc.php\nChecking lib/bootstrap.inc.php\nmode: 100644 type: blob blob: 59d6fb573504abcc6c34aabec85fc73717e828bf\nfilename: lib/client_process.class.php\nChecking lib/client_process.class.php\nmode: 100644 type: blob blob: e3549d6a6f9ba62efb620bdf4127febad8a876b4\nfilename: lib/controllers/CcdeployController.php\nChecking lib/controllers/CcdeployController.php\nmode: 100644 type: blob blob: 74c9b9496a5e75ed39d35ec38fe907f0d1334f9a\nfilename: lib/controllers/ClientDbController.php\nChecking lib/controllers/ClientDbController.php\nmode: 100644 type: blob blob: 2d22560230ec3fe2d2ccc05439898b204243ec41\nfilename: lib/controllers/ClientInfoController.php\nChecking lib/controllers/ClientInfoController.php\nmode: 100644 type: blob blob: 2e22593ef858f53550132b0d9a200890dbfcbc30\nfilename: lib/controllers/ClientTarballController.php\nChecking lib/controllers/ClientTarballController.php\nmode: 100644 type: blob blob: c04828ac194914b9679e9a548e0331d891b9d59c\nfilename: lib/controllers/DeployController.php\nChecking lib/controllers/DeployController.php\nmode: 100644 type: blob blob: 12568d637a490c54708bb34b7103c3fd71cb4dc0\nfilename: lib/controllers/GenerateCreateScriptController.php\nChecking lib/controllers/GenerateCreateScriptController.php\nmode: 100644 type: blob blob: 081e4b213cbd5dc6d4459b932db1f7aea267de0d\nfilename: lib/controllers/GenerateUpgradeScriptController.php\nChecking lib/controllers/GenerateUpgradeScriptController.php\nmode: 100644 type: blob blob: 558ddc9f9aa73556791c19c946b6b4d359a07cab\nfilename: lib/controllers/ListClientsController.php\nChecking lib/controllers/ListClientsController.php\nmode: 100644 type: blob blob: 37fc6c28d4cce9bf48513a67d04c50692be69525\nfilename: lib/controllers/ListPackagesController.php\nChecking lib/controllers/ListPackagesController.php\nmode: 100644 type: blob blob: 225d5c4303962561cc36b7132e28ddb62099d52b\nfilename: lib/controllers/ListVersionsController.php\nChecking lib/controllers/ListVersionsController.php\nmode: 100644 type: blob blob: 0c814e7a8e880af7df96d5c4a3d6c77226bfbd4f\nfilename: lib/controllers/PrepareController.php\nChecking lib/controllers/PrepareController.php\nmode: 100644 type: blob blob: db3b743c3fe111fbd0b83448d419bd1e3d063d85\nfilename: lib/controllers/RollbackController.php\nChecking lib/controllers/RollbackController.php\nmode: 100644 type: blob blob: 9f12afed32cb26f617b0f2d2019fc084aea2d3dc\nfilename: lib/controllers/ServerUpdateController.php\nChecking lib/controllers/ServerUpdateController.php\nmode: 100644 type: blob blob: dca23654205f7e537769f8cd6a463377f5f61313\nfilename: lib/controllers/TestServersController.php\nChecking lib/controllers/TestServersController.php\nmode: 100644 type: blob blob: a15750987e7ad9d0ace814128cccd9af5bfab067\nfilename: lib/controllers/UpgradeController.php\nChecking lib/controllers/UpgradeController.php\nmode: 100644 type: blob blob: e8be9364b4b75a49dcb1bced52a76987791291a8\nfilename: lib/controllers/WriteDbConfigController.php\nChecking lib/controllers/WriteDbConfigController.php\nmode: 100644 type: blob blob: 4a97a4e122adc85db2d86273c59331881b6b8a7d\nfilename: lib/data/client__client_group.data.php\nChecking lib/data/client__client_group.data.php\nmode: 100644 type: blob blob: eb4b609dfba994b46159a60baa48f4e730d119d9\nfilename: lib/data/client__deploy_status.data.php\nChecking lib/data/client__deploy_status.data.php\nmode: 100644 type: blob blob: 4fdb4d9af394cc9224147cd54a81da7823336ead\nfilename: lib/data/client__package.data.php\nChecking lib/data/client__package.data.php\nmode: 100644 type: blob blob: cc343c87f754925ad55aeb029851f424fe4070d9\nfilename: lib/data/client_db_credentials.data.php\nChecking lib/data/client_db_credentials.data.php\nmode: 100644 type: blob blob: ed5777877daced5328a87826afcbbcaf27e2eb6f\nfilename: lib/data/client_group.data.php\nChecking lib/data/client_group.data.php\nmode: 100644 type: blob blob: 3efda2cf91c8af698a4314131c399ea835c2698d\nfilename: lib/data/clientconfig.data.php\nChecking lib/data/clientconfig.data.php\nmode: 100644 type: blob blob: d1e98c9162dc8245241024c96d20e8bd6d9add08\nfilename: lib/data/command.data.php\nChecking lib/data/command.data.php\nmode: 100644 type: blob blob: 8253f88e62ae965ee3b34b86f0427fdb3e9e9c9c\nfilename: lib/data/command_exception.data.php\nChecking lib/data/command_exception.data.php\nmode: 100644 type: blob blob: 2724fb1aaf3215330e82c18df3bb5cf48d1ed290\nfilename: lib/data/package.data.php\nChecking lib/data/package.data.php\nmode: 100644 type: blob blob: f2c5703f7976b1dfe9b5e2af8699092905a2f114\nfilename: lib/data/package_action.data.php\nChecking lib/data/package_action.data.php\nmode: 100644 type: blob blob: 80c78ddedc68659cf37969513d570200cf80a3ae\nfilename: lib/data/package_action__server.data.php\nChecking lib/data/package_action__server.data.php\nmode: 100644 type: blob blob: b76feab0a01b7f384721683b5d7525c76e5c0f56\nfilename: lib/data/package_version.data.php\nChecking lib/data/package_version.data.php\nmode: 100644 type: blob blob: a4d828188ee38d89d165e59bbc34d7beafd6bc62\nfilename: lib/data/prepared_package.data.php\nChecking lib/data/prepared_package.data.php\nmode: 100644 type: blob blob: 61895931ce58a9353a419a809fad0c88c6d6b6bc\nfilename: lib/data/server.data.php\nChecking lib/data/server.data.php\nmode: 100644 type: blob blob: ab265140deec0e0e83344d54878040a5f72470c1\nfilename: lib/fork.php\nChecking lib/fork.php\nmode: 100644 type: blob blob: bd5b8e9648afd2ab87730ad1dfeea5651a038ff4\nfilename: lib/model_rules/generate_create_script_rules.class.php\nChecking lib/model_rules/generate_create_script_rules.class.php\nmode: 100644 type: blob blob: 7677f4f5c22112913e8fcba3552943c04e12bfbd\nfilename: lib/model_rules/generate_upgrade_script_rules.class.php\nChecking lib/model_rules/generate_upgrade_script_rules.class.php\nmode: 100644 type: blob blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\nfilename: lib/packages/ee.php\nChecking lib/packages/ee.php\nmode: 100644 type: blob blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\nfilename: lib/packages/framework.php\nChecking lib/packages/framework.php\nmode: 100644 type: blob blob: 392bf1322466b7fbec368cea554e76639bd5a340\nfilename: lib/rules/client_spec_rules.class.php\nChecking lib/rules/client_spec_rules.class.php\nmode: 100644 type: blob blob: 282968efad5ec81313b9dde87e7701515d571bf6\nfilename: lib/rules/rulesets/client_spec_ruleset.class.php\nChecking lib/rules/rulesets/client_spec_ruleset.class.php\nmode: 100644 type: blob blob: 15ea52e6f84ffdd75cf9a9185b8e82adffbf6a41\nfilename: lib/views/cli/ApproveCreateScript/index.php\nChecking lib/views/cli/ApproveCreateScript/index.php\nmode: 100644 type: blob blob: 5add2d63da8b4d0dc200b17479416ce3e19c829b\nfilename: lib/views/cli/ApproveUpgradeScript/index.php\nChecking lib/views/cli/ApproveUpgradeScript/index.php\nmode: 100644 type: blob blob: ffb26436f4de184d11246ae7733154e0146cf27e\nfilename: lib/views/cli/ClientInfo/index.php\nChecking lib/views/cli/ClientInfo/index.php\nmode: 100644 type: blob blob: 0e2e27d075d304d110eae6be6c882fdfedd23106\nfilename: lib/views/cli/Deploy/help.php\nChecking lib/views/cli/Deploy/help.php\nmode: 100644 type: blob blob: ec17db9d9bab632c1e547f2ac6a677a16ceea899\nfilename: lib/views/cli/Deploy/index.php\nChecking lib/views/cli/Deploy/index.php\nmode: 100644 type: blob blob: 85ebed31e40022abb5ba3b1ca4ffa9087b1e2969\nfilename: lib/views/cli/Error/index.php\nChecking lib/views/cli/Error/index.php\nmode: 100644 type: blob blob: cba0e73c2feed28a20cd58a3f4fe0b4c9828ccef\nfilename: lib/views/cli/GenerateCreateScript/index.php\nChecking lib/views/cli/GenerateCreateScript/index.php\nmode: 100644 type: blob blob: cd36ee08d3985be02960a5767fe47f3b971595ca\nfilename: lib/views/cli/GenerateUpgradeScript/index.php\nChecking lib/views/cli/GenerateUpgradeScript/index.php\nmode: 100644 type: blob blob: 6001717f37ff194ef465e5c5e3bfdeecc4155a5a\nfilename: lib/views/cli/ListClients/help.php\nChecking lib/views/cli/ListClients/help.php\nmode: 100644 type: blob blob: ba741522b3cc80cb03bb8fa893158f5956a4b135\nfilename: lib/views/cli/ListClients/index.php\nChecking lib/views/cli/ListClients/index.php\nmode: 100644 type: blob blob: a82be806ff53d1cd428efc095358ba51b7b194be\nfilename: lib/views/cli/ListPackages/help.php\nChecking lib/views/cli/ListPackages/help.php\nmode: 100644 type: blob blob: 5a2f724ad94c1d5650d62b971a4cd6d6c4bd7826\nfilename: lib/views/cli/ListPackages/index.php\nChecking lib/views/cli/ListPackages/index.php\nmode: 100644 type: blob blob: 4faf3a7631ad89aa74dcb41362b78de0af5af2ab\nfilename: lib/views/cli/ListVersions/help.php\nChecking lib/views/cli/ListVersions/help.php\nmode: 100644 type: blob blob: 7e26a74730ddc5ac282de483e7b1951a0c0a7ac2\nfilename: lib/views/cli/ListVersions/index.php\nChecking lib/views/cli/ListVersions/index.php\nmode: 100644 type: blob blob: 3609700fb37f9919222ce0600eb2329aad3d5615\nfilename: lib/views/cli/Prepare/help.php\nChecking lib/views/cli/Prepare/help.php\nmode: 100644 type: blob blob: 567d8074e044e180251f94232ab3ffe386e01e6b\nfilename: lib/views/cli/Prepare/index.php\nChecking lib/views/cli/Prepare/index.php\nmode: 100644 type: blob blob: eb12d2ddedde8dec0514c4711dd055af30156b19\nfilename: lib/views/cli/ServerUpdate/index.php\nChecking lib/views/cli/ServerUpdate/index.php\nmode: 100644 type: blob blob: 0fdbb9cbe18b682e866f33e6bdcec587a5227784\nfilename: lib/views/cli/Upgrade/help.php\nChecking lib/views/cli/Upgrade/help.php\nmode: 100644 type: blob blob: 7877eac48fc7ed8a979504413d333f7aabe97b62\nfilename: lib/views/cli/layouts/application.php\nChecking lib/views/cli/layouts/application.php\nmode: 100644 type: blob blob: 9af564990a00f91e00f373f7f25970529a0e0e87\nfilename: lib/views/cli/shared/_standardOptions.php\nChecking lib/views/cli/shared/_standardOptions.php\nmode: 100644 type: blob blob: 5fdfefcd2edfc190565af4a7b995fc84729bec35\nfilename: lib/views/cli/shared/_validationErrors.php\nChecking lib/views/cli/shared/_validationErrors.php\nmode: 100644 type: blob blob: 0710b520db1e6beba4c9bbf14eaee6fa8dd9d68a\nfilename: lib/views/html/Deploy/help.php\nChecking lib/views/html/Deploy/help.php\nmode: 100644 type: blob blob: ae03e2ee5b2845b705fac383903787fcef61dd4b\nfilename: lib/views/html/Error/index.php\nChecking lib/views/html/Error/index.php\nmode: 100644 type: blob blob: fcd069bb109fa8689987fa541fd6eb4f7ce78165\nfilename: lib/views/html/ListClients/help.php\nChecking lib/views/html/ListClients/help.php\nmode: 100644 type: blob blob: ef99eaf1eae653db24195724847808173a8c421a\nfilename: lib/views/html/ListClients/index.php\nChecking lib/views/html/ListClients/index.php\nmode: 100644 type: blob blob: fd0592aa00ab76081b42579f94e5b8a26e4c83a8\nfilename: lib/views/html/ListClients/input.php\nChecking lib/views/html/ListClients/input.php\nmode: 100644 type: blob blob: 917befbf76d3658cbb769c351563d5cf115f5f3e\nfilename: lib/views/html/ListPackages/help.php\nChecking lib/views/html/ListPackages/help.php\nmode: 100644 type: blob blob: 083b172802ec09cac79a209c343a7c0ec5605e47\nfilename: lib/views/html/ListPackages/index.php\nChecking lib/views/html/ListPackages/index.php\nmode: 100644 type: blob blob: a2f62f2e826dcc96b6c7aa0eac30067884f4971e\nfilename: lib/views/html/ListVersions/help.php\nChecking lib/views/html/ListVersions/help.php\nmode: 100644 type: blob blob: 9ee8a316bfbad950389500a334806bbdbe7efcf1\nfilename: lib/views/html/ListVersions/index.php\nChecking lib/views/html/ListVersions/index.php\nmode: 100644 type: blob blob: ffa4ce8ca633ca8e8d7cf818b091e89301972d25\nfilename: lib/views/html/layouts/application.php\nChecking lib/views/html/layouts/application.php\nmode: 100644 type: blob blob: 8a0cf604dbe88d41bbf18b27562c61b71612e6e3\nfilename: lib/views/html/shared/_standardOptions.php\nChecking lib/views/html/shared/_standardOptions.php\nmode: 100644 type: blob blob: 3f9c8db23f4517fa0aff311b6036324dbbf1547e\nfilename: lib/views/html/shared/_validationErrors.php\nChecking lib/views/html/shared/_validationErrors.php\nmode: 100755 type: blob blob: 0ed20cbaa2ebefc6b473ef19e2f0534916fe8401\nfilename: scripts/clean_sandbox.sh\nmode: 100755 type: blob blob: 3460ac158ec6e49d18947659a88f89fee6742005\nfilename: scripts/client_atomicity_cutover.sh\nmode: 100755 type: blob blob: 605fe7efe119e13e608010c500e8d46a9aa78678\nfilename: scripts/consolidate-links.py\nmode: 100755 type: blob blob: 937fd93c9dec4ccbd097a0c738308e294555e074\nfilename: scripts/cutover_client.sh\nmode: 100755 type: blob blob: 8de04dd40f433abc83e55694c0b18fe8e8a4be5f\nfilename: scripts/mk_client_repos.sh\nmode: 100755 type: blob blob: 683e36ed7736d8dafaff73ddc25d8eceb2184ff7\nfilename: scripts/new_client_setup.sh\nmode: 100755 type: blob blob: 50215aad6a97654524a19cec45863c22f75338de\nfilename: scripts/push_branch.sh\nmode: 100755 type: blob blob: b562aef0d6184919a1867d38d884cec8b5d0b8cb\nfilename: scripts/release/create-migrations.sh\nmode: 100755 type: blob blob: 85161b45e9cda0d9c11ae855ebe7f9352fef624a\nfilename: scripts/release/deploy-mailer-compat.sh\nmode: 100755 type: blob blob: c3d147d2129320941d9ffba072f29378fae6f6f2\nfilename: scripts/release/find-merged-branches.sh\nmode: 100755 type: blob blob: 81e81767bb05fa037598e308e4870f08fff8314e\nfilename: scripts/release/mailer-compat.sh\nmode: 100755 type: blob blob: 84db6a40b1aaefe87d62f06a86f566041563e6a5\nfilename: scripts/release/tag-deploy-config.sh\nmode: 100755 type: blob blob: 5a359fff5e6c0590c3bcea43b16420217f50a285\nfilename: scripts/release/tag-release.sh\nmode: 100755 type: blob blob: ce1256c79a87e7d6e34f6d8dd539e6cb7187d595\nfilename: scripts/remove_cvs_dirs.sh\nmode: 100755 type: blob blob: f2941728666e41d44c0a90b1f3640920de3bb99f\nfilename: scripts/remove_cvs_dirs_group.sh\nmode: 100755 type: blob blob: 0a1a3e1cc43f693f941405030318d0ee55379d5b\nfilename: scripts/remove_cvs_dirs_server.sh\nmode: 100755 type: blob blob: 52d399655cba3f4dbf6b052a44626cad2136d9a2\nfilename: scripts/remove_scratch_dirs.sh\nmode: 100755 type: blob blob: 5cb2eed1bb0ce1e3f59f5e0bba2f39cf1578b433\nfilename: scripts/shared_resources_client_update.sh\nmode: 100755 type: blob blob: f6fd4a715ff2165e58e7ae469b7f2beffd10683e\nfilename: scripts/show_cv.sh\nmode: 100755 type: blob blob: 2c6fdbff1cc764d17162f4c926ac19c5e7a3771e\nfilename: scripts/show_cv_json.sh\nmode: 100644 type: blob blob: 0d1fa845d2d1cfc068df2c3d91408b1ff8ea428f\nfilename: test/.gitignore\nmode: 100644 type: blob blob: c8a970f86b3279c824e750304ae7dcd1c671f9ef\nfilename: test/BlueTestCase.php\nChecking test/BlueTestCase.php\nmode: 100644 type: blob blob: a46ad98c60b25e344e35a7ece5581ed8da8ba37b\nfilename: test/BlueTestSuite.php\nChecking test/BlueTestSuite.php\nmode: 100644 type: blob blob: d649763699177b566c060471eba98ef0d6b60934\nfilename: test/CommandExposer.php\nChecking test/CommandExposer.php\nmode: 100755 type: blob blob: 14740e1d5b8110d4bd61a01b46f2dd55a030016b\nfilename: test/bsdunit\nmode: 100644 type: blob blob: 8c4c794ff20baf349c966a03a5d78e1ae0151b31\nfilename: test/fixtures/ClientConfigFixtures.php\nChecking test/fixtures/ClientConfigFixtures.php\nmode: 100644 type: blob blob: a3a3c4b4a349ac8d322187b3e638cc8b7c4a853f\nfilename: test/morebogus.php\nChecking test/morebogus.php\nThere was a syntax error in 'test/morebogus.php'.  Rejecting this\nattempted merge!\nerror: hooks/pre-receive exited with error code 1\nTo ssh://git.bluestatedigital.com/home/git/bsdrelease\n ! [remote rejected] bug-28046 -> bug-28046 (pre-receive hook declined)\nerror: failed to push some refs to\n'ssh://git.bluestatedigital.com/home/git/bsdrelease'\n[17:01][admin@Chris-Patti:~/src/bsdrelease/test(bug-28046)]$\n\nWhy is git ls-tree returning all those blobs that are totally\nunrelated to my check-in, and how can I constrain the files I'm syntax\nchecking to only those in the current commit?\n\nThanks for any insights!\n-Chris\n(The hook source is at: http://pastebin.com/TVXVfDVi and also directly\nbelow.  I used PHP because this is a 100% PHP shop, but I'm reasonably\ncertain that's not the issue.)\n---\n#!/home/php/bin/php\n<?php\n\n$fpstdin = fopen(\"php://stdin\",\"r\");\n\n$line = fgets($fpstdin);\n\nlist($old_sha1,$new_sha1,$refname)=explode(\" \",$line);\n\necho \"ns: $new_sha1\\n\";\necho \"os: $old_sha1\\n\";\necho \"refname: $refname\\n\";\n\n$lstree = array();\n\nexec(\"git ls-tree -r $new_sha1\",$lstree,$lsrcval);\nif ($lsrcval != 0) {\n        echo \"Syntax checker hook is malfunctioning.  Can't execute\ngit ls-tree.  Failing gracefully and allowing this push.\\n\";\n};\n\n# If we can execute the git ls-tree I'm assuming we have access to a\nworking git.\n\n\nforeach ($lstree as &$lstline) {\n        list($rest,$filename) = explode('       ',$lstline);\n        list($mode,$type,$blob) = explode(\" \",$rest);\n        echo \"mode: $mode type: $type blob: $blob filename: $filename\\n\";\n\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\nexit(0);\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149299","messageId":"4C7B8E1E.6050708@drmicha.warpmail.net","threadId":"24891","inReplyTo":"AANLkTikktdPoZN8MwJD+Gxus16xBGtScCAqT9W0eiWAb@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-08-30T10:55:26Z","receivedAt":"2010-08-30T10:55:26Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Chris Patti venit, vidit, dixit 27.08.2010 23:07:\n> Folks;\n> \n> I'm trying to write a pre-receive hook to prevent syntactically bogus\n> PHP files from being 'push'ed into our master repository.\n> \n> It's puzzling, my hook works *perfectly* on two different test repos,\n> but when I try to utilize it in an environment with lots of complex\n> branching, it exhibits totally (to me) unexplained behavior and fails\n> utterly.\n> \n> Here's the correct behavior, in my test environments.  moo.php does\n> indeed have a syntax error.  foo.php is syntactically correct:\n> \n> ---\n> [16:50][admin@Chris-Patti:~/src/relengtest(master)]$ git push origin master\n> Counting objects: 5, done.\n> Delta compression using up to 2 threads.\n> Compressing objects: 100% (3/3), done.\n> Writing objects: 100% (3/3), 363 bytes, done.\n> Total 3 (delta 0), reused 0 (delta 0)\n> ns: d372eddeb4a6bb69576c96458040c6bf44cdee79\n> os: f93a54b5bccc1630b61894f5041c0c6e105b47a3\n> refname: refs/heads/master\n> \n> mode: 100644 type: blob blob: 372c38001f74f92264f77d448af27d8f6225db96\n> filename: foo.php\n> Checking foo.php\n> mode: 100644 type: blob blob: c10ecdacc38543a880c984a478a8c62399d22e81\n> filename: moo.php\n> Checking moo.php\n> There was a syntax error in 'moo.php'.  Rejecting this attempted merge!\n> error: hooks/pre-receive exited with error code 1\n> To ssh://git.bluestatedigital.com/home/git/relengtest.git\n>  ! [remote rejected] master -> master (pre-receive hook declined)\n> error: failed to push some refs to\n> 'ssh://git.bluestatedigital.com/home/git/relengtest.git'\n> [16:50][admin@Chris-Patti:~/src/relengtest(master)]$\n> \n> ---\n> \n> Great, right?  I'm taking the old and new refs in, doing git ls-tree\n> on the new_sha1 value to get the list of all the files included in\n> this commit,a nd their blob ids, and then using git show to get the\n> files contents and run them through the syntax checker.\n> \n> Only, here's what happens when I put the identical hook into a\n> repository where I'm using a branch off a branch:\n> ---\n> [17:01][admin@Chris-Patti:~/src/bsdrelease/test(bug-28046)]$ git push\n> origin bug-28046\n> Counting objects: 7, done.\n> Delta compression using up to 2 threads.\n> Compressing objects: 100% (4/4), done.\n> Writing objects: 100% (4/4), 399 bytes, done.\n> Total 4 (delta 3), reused 0 (delta 0)\n> ns: d17233cfa4a7ae650a7fe0a97d336890a29a68c1\n> os: ad8e2e4f9510e1fbbd3ab58a58bf218ee2aa7150\n> refname: refs/heads/bug-28046\n> \n> mode: 100644 type: blob blob: 9e2244625c3636978e8b44bce4ab2eb55bd100d6\n> filename: .gitignore\n> mode: 100755 type: blob blob: 9c1f0855a64f5ec0be3eebb9069ab2393602d662\n> filename: bin/bsdrelease\n> mode: 100755 type: blob blob: da2500c7f14cee33ab63477825390a8b7f22b74d\n> filename: bin/upgrade\n> mode: 100644 type: blob blob: a93a7616245d104711261a2dcaf71ff535aac737\n> filename: lib/Horde/Argv/Parser.php\n> Checking lib/Horde/Argv/Parser.php\n> mode: 100644 type: blob blob: 42337c2865ee6ace45afcf11c6dfd13b10ac36c6\n> filename: lib/Horde/Controller/Dispatcher.php\n> Checking lib/Horde/Controller/Dispatcher.php\n> mode: 100644 type: blob blob: 59f867badec965bf03c30eb06da0eb45c85aa033\n> filename: lib/Horde/Support/Inflector.php\n> Checking lib/Horde/Support/Inflector.php\n> mode: 100644 type: blob blob: f36f36d22ad9fa7dc1002d5d39926046a8505d58\n> filename: lib/bootstrap.inc.php\n> Checking lib/bootstrap.inc.php\n> mode: 100644 type: blob blob: 59d6fb573504abcc6c34aabec85fc73717e828bf\n> filename: lib/client_process.class.php\n> Checking lib/client_process.class.php\n> mode: 100644 type: blob blob: e3549d6a6f9ba62efb620bdf4127febad8a876b4\n> filename: lib/controllers/CcdeployController.php\n> Checking lib/controllers/CcdeployController.php\n> mode: 100644 type: blob blob: 74c9b9496a5e75ed39d35ec38fe907f0d1334f9a\n> filename: lib/controllers/ClientDbController.php\n> Checking lib/controllers/ClientDbController.php\n> mode: 100644 type: blob blob: 2d22560230ec3fe2d2ccc05439898b204243ec41\n> filename: lib/controllers/ClientInfoController.php\n> Checking lib/controllers/ClientInfoController.php\n> mode: 100644 type: blob blob: 2e22593ef858f53550132b0d9a200890dbfcbc30\n> filename: lib/controllers/ClientTarballController.php\n> Checking lib/controllers/ClientTarballController.php\n> mode: 100644 type: blob blob: c04828ac194914b9679e9a548e0331d891b9d59c\n> filename: lib/controllers/DeployController.php\n> Checking lib/controllers/DeployController.php\n> mode: 100644 type: blob blob: 12568d637a490c54708bb34b7103c3fd71cb4dc0\n> filename: lib/controllers/GenerateCreateScriptController.php\n> Checking lib/controllers/GenerateCreateScriptController.php\n> mode: 100644 type: blob blob: 081e4b213cbd5dc6d4459b932db1f7aea267de0d\n> filename: lib/controllers/GenerateUpgradeScriptController.php\n> Checking lib/controllers/GenerateUpgradeScriptController.php\n> mode: 100644 type: blob blob: 558ddc9f9aa73556791c19c946b6b4d359a07cab\n> filename: lib/controllers/ListClientsController.php\n> Checking lib/controllers/ListClientsController.php\n> mode: 100644 type: blob blob: 37fc6c28d4cce9bf48513a67d04c50692be69525\n> filename: lib/controllers/ListPackagesController.php\n> Checking lib/controllers/ListPackagesController.php\n> mode: 100644 type: blob blob: 225d5c4303962561cc36b7132e28ddb62099d52b\n> filename: lib/controllers/ListVersionsController.php\n> Checking lib/controllers/ListVersionsController.php\n> mode: 100644 type: blob blob: 0c814e7a8e880af7df96d5c4a3d6c77226bfbd4f\n> filename: lib/controllers/PrepareController.php\n> Checking lib/controllers/PrepareController.php\n> mode: 100644 type: blob blob: db3b743c3fe111fbd0b83448d419bd1e3d063d85\n> filename: lib/controllers/RollbackController.php\n> Checking lib/controllers/RollbackController.php\n> mode: 100644 type: blob blob: 9f12afed32cb26f617b0f2d2019fc084aea2d3dc\n> filename: lib/controllers/ServerUpdateController.php\n> Checking lib/controllers/ServerUpdateController.php\n> mode: 100644 type: blob blob: dca23654205f7e537769f8cd6a463377f5f61313\n> filename: lib/controllers/TestServersController.php\n> Checking lib/controllers/TestServersController.php\n> mode: 100644 type: blob blob: a15750987e7ad9d0ace814128cccd9af5bfab067\n> filename: lib/controllers/UpgradeController.php\n> Checking lib/controllers/UpgradeController.php\n> mode: 100644 type: blob blob: e8be9364b4b75a49dcb1bced52a76987791291a8\n> filename: lib/controllers/WriteDbConfigController.php\n> Checking lib/controllers/WriteDbConfigController.php\n> mode: 100644 type: blob blob: 4a97a4e122adc85db2d86273c59331881b6b8a7d\n> filename: lib/data/client__client_group.data.php\n> Checking lib/data/client__client_group.data.php\n> mode: 100644 type: blob blob: eb4b609dfba994b46159a60baa48f4e730d119d9\n> filename: lib/data/client__deploy_status.data.php\n> Checking lib/data/client__deploy_status.data.php\n> mode: 100644 type: blob blob: 4fdb4d9af394cc9224147cd54a81da7823336ead\n> filename: lib/data/client__package.data.php\n> Checking lib/data/client__package.data.php\n> mode: 100644 type: blob blob: cc343c87f754925ad55aeb029851f424fe4070d9\n> filename: lib/data/client_db_credentials.data.php\n> Checking lib/data/client_db_credentials.data.php\n> mode: 100644 type: blob blob: ed5777877daced5328a87826afcbbcaf27e2eb6f\n> filename: lib/data/client_group.data.php\n> Checking lib/data/client_group.data.php\n> mode: 100644 type: blob blob: 3efda2cf91c8af698a4314131c399ea835c2698d\n> filename: lib/data/clientconfig.data.php\n> Checking lib/data/clientconfig.data.php\n> mode: 100644 type: blob blob: d1e98c9162dc8245241024c96d20e8bd6d9add08\n> filename: lib/data/command.data.php\n> Checking lib/data/command.data.php\n> mode: 100644 type: blob blob: 8253f88e62ae965ee3b34b86f0427fdb3e9e9c9c\n> filename: lib/data/command_exception.data.php\n> Checking lib/data/command_exception.data.php\n> mode: 100644 type: blob blob: 2724fb1aaf3215330e82c18df3bb5cf48d1ed290\n> filename: lib/data/package.data.php\n> Checking lib/data/package.data.php\n> mode: 100644 type: blob blob: f2c5703f7976b1dfe9b5e2af8699092905a2f114\n> filename: lib/data/package_action.data.php\n> Checking lib/data/package_action.data.php\n> mode: 100644 type: blob blob: 80c78ddedc68659cf37969513d570200cf80a3ae\n> filename: lib/data/package_action__server.data.php\n> Checking lib/data/package_action__server.data.php\n> mode: 100644 type: blob blob: b76feab0a01b7f384721683b5d7525c76e5c0f56\n> filename: lib/data/package_version.data.php\n> Checking lib/data/package_version.data.php\n> mode: 100644 type: blob blob: a4d828188ee38d89d165e59bbc34d7beafd6bc62\n> filename: lib/data/prepared_package.data.php\n> Checking lib/data/prepared_package.data.php\n> mode: 100644 type: blob blob: 61895931ce58a9353a419a809fad0c88c6d6b6bc\n> filename: lib/data/server.data.php\n> Checking lib/data/server.data.php\n> mode: 100644 type: blob blob: ab265140deec0e0e83344d54878040a5f72470c1\n> filename: lib/fork.php\n> Checking lib/fork.php\n> mode: 100644 type: blob blob: bd5b8e9648afd2ab87730ad1dfeea5651a038ff4\n> filename: lib/model_rules/generate_create_script_rules.class.php\n> Checking lib/model_rules/generate_create_script_rules.class.php\n> mode: 100644 type: blob blob: 7677f4f5c22112913e8fcba3552943c04e12bfbd\n> filename: lib/model_rules/generate_upgrade_script_rules.class.php\n> Checking lib/model_rules/generate_upgrade_script_rules.class.php\n> mode: 100644 type: blob blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> filename: lib/packages/ee.php\n> Checking lib/packages/ee.php\n> mode: 100644 type: blob blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> filename: lib/packages/framework.php\n> Checking lib/packages/framework.php\n> mode: 100644 type: blob blob: 392bf1322466b7fbec368cea554e76639bd5a340\n> filename: lib/rules/client_spec_rules.class.php\n> Checking lib/rules/client_spec_rules.class.php\n> mode: 100644 type: blob blob: 282968efad5ec81313b9dde87e7701515d571bf6\n> filename: lib/rules/rulesets/client_spec_ruleset.class.php\n> Checking lib/rules/rulesets/client_spec_ruleset.class.php\n> mode: 100644 type: blob blob: 15ea52e6f84ffdd75cf9a9185b8e82adffbf6a41\n> filename: lib/views/cli/ApproveCreateScript/index.php\n> Checking lib/views/cli/ApproveCreateScript/index.php\n> mode: 100644 type: blob blob: 5add2d63da8b4d0dc200b17479416ce3e19c829b\n> filename: lib/views/cli/ApproveUpgradeScript/index.php\n> Checking lib/views/cli/ApproveUpgradeScript/index.php\n> mode: 100644 type: blob blob: ffb26436f4de184d11246ae7733154e0146cf27e\n> filename: lib/views/cli/ClientInfo/index.php\n> Checking lib/views/cli/ClientInfo/index.php\n> mode: 100644 type: blob blob: 0e2e27d075d304d110eae6be6c882fdfedd23106\n> filename: lib/views/cli/Deploy/help.php\n> Checking lib/views/cli/Deploy/help.php\n> mode: 100644 type: blob blob: ec17db9d9bab632c1e547f2ac6a677a16ceea899\n> filename: lib/views/cli/Deploy/index.php\n> Checking lib/views/cli/Deploy/index.php\n> mode: 100644 type: blob blob: 85ebed31e40022abb5ba3b1ca4ffa9087b1e2969\n> filename: lib/views/cli/Error/index.php\n> Checking lib/views/cli/Error/index.php\n> mode: 100644 type: blob blob: cba0e73c2feed28a20cd58a3f4fe0b4c9828ccef\n> filename: lib/views/cli/GenerateCreateScript/index.php\n> Checking lib/views/cli/GenerateCreateScript/index.php\n> mode: 100644 type: blob blob: cd36ee08d3985be02960a5767fe47f3b971595ca\n> filename: lib/views/cli/GenerateUpgradeScript/index.php\n> Checking lib/views/cli/GenerateUpgradeScript/index.php\n> mode: 100644 type: blob blob: 6001717f37ff194ef465e5c5e3bfdeecc4155a5a\n> filename: lib/views/cli/ListClients/help.php\n> Checking lib/views/cli/ListClients/help.php\n> mode: 100644 type: blob blob: ba741522b3cc80cb03bb8fa893158f5956a4b135\n> filename: lib/views/cli/ListClients/index.php\n> Checking lib/views/cli/ListClients/index.php\n> mode: 100644 type: blob blob: a82be806ff53d1cd428efc095358ba51b7b194be\n> filename: lib/views/cli/ListPackages/help.php\n> Checking lib/views/cli/ListPackages/help.php\n> mode: 100644 type: blob blob: 5a2f724ad94c1d5650d62b971a4cd6d6c4bd7826\n> filename: lib/views/cli/ListPackages/index.php\n> Checking lib/views/cli/ListPackages/index.php\n> mode: 100644 type: blob blob: 4faf3a7631ad89aa74dcb41362b78de0af5af2ab\n> filename: lib/views/cli/ListVersions/help.php\n> Checking lib/views/cli/ListVersions/help.php\n> mode: 100644 type: blob blob: 7e26a74730ddc5ac282de483e7b1951a0c0a7ac2\n> filename: lib/views/cli/ListVersions/index.php\n> Checking lib/views/cli/ListVersions/index.php\n> mode: 100644 type: blob blob: 3609700fb37f9919222ce0600eb2329aad3d5615\n> filename: lib/views/cli/Prepare/help.php\n> Checking lib/views/cli/Prepare/help.php\n> mode: 100644 type: blob blob: 567d8074e044e180251f94232ab3ffe386e01e6b\n> filename: lib/views/cli/Prepare/index.php\n> Checking lib/views/cli/Prepare/index.php\n> mode: 100644 type: blob blob: eb12d2ddedde8dec0514c4711dd055af30156b19\n> filename: lib/views/cli/ServerUpdate/index.php\n> Checking lib/views/cli/ServerUpdate/index.php\n> mode: 100644 type: blob blob: 0fdbb9cbe18b682e866f33e6bdcec587a5227784\n> filename: lib/views/cli/Upgrade/help.php\n> Checking lib/views/cli/Upgrade/help.php\n> mode: 100644 type: blob blob: 7877eac48fc7ed8a979504413d333f7aabe97b62\n> filename: lib/views/cli/layouts/application.php\n> Checking lib/views/cli/layouts/application.php\n> mode: 100644 type: blob blob: 9af564990a00f91e00f373f7f25970529a0e0e87\n> filename: lib/views/cli/shared/_standardOptions.php\n> Checking lib/views/cli/shared/_standardOptions.php\n> mode: 100644 type: blob blob: 5fdfefcd2edfc190565af4a7b995fc84729bec35\n> filename: lib/views/cli/shared/_validationErrors.php\n> Checking lib/views/cli/shared/_validationErrors.php\n> mode: 100644 type: blob blob: 0710b520db1e6beba4c9bbf14eaee6fa8dd9d68a\n> filename: lib/views/html/Deploy/help.php\n> Checking lib/views/html/Deploy/help.php\n> mode: 100644 type: blob blob: ae03e2ee5b2845b705fac383903787fcef61dd4b\n> filename: lib/views/html/Error/index.php\n> Checking lib/views/html/Error/index.php\n> mode: 100644 type: blob blob: fcd069bb109fa8689987fa541fd6eb4f7ce78165\n> filename: lib/views/html/ListClients/help.php\n> Checking lib/views/html/ListClients/help.php\n> mode: 100644 type: blob blob: ef99eaf1eae653db24195724847808173a8c421a\n> filename: lib/views/html/ListClients/index.php\n> Checking lib/views/html/ListClients/index.php\n> mode: 100644 type: blob blob: fd0592aa00ab76081b42579f94e5b8a26e4c83a8\n> filename: lib/views/html/ListClients/input.php\n> Checking lib/views/html/ListClients/input.php\n> mode: 100644 type: blob blob: 917befbf76d3658cbb769c351563d5cf115f5f3e\n> filename: lib/views/html/ListPackages/help.php\n> Checking lib/views/html/ListPackages/help.php\n> mode: 100644 type: blob blob: 083b172802ec09cac79a209c343a7c0ec5605e47\n> filename: lib/views/html/ListPackages/index.php\n> Checking lib/views/html/ListPackages/index.php\n> mode: 100644 type: blob blob: a2f62f2e826dcc96b6c7aa0eac30067884f4971e\n> filename: lib/views/html/ListVersions/help.php\n> Checking lib/views/html/ListVersions/help.php\n> mode: 100644 type: blob blob: 9ee8a316bfbad950389500a334806bbdbe7efcf1\n> filename: lib/views/html/ListVersions/index.php\n> Checking lib/views/html/ListVersions/index.php\n> mode: 100644 type: blob blob: ffa4ce8ca633ca8e8d7cf818b091e89301972d25\n> filename: lib/views/html/layouts/application.php\n> Checking lib/views/html/layouts/application.php\n> mode: 100644 type: blob blob: 8a0cf604dbe88d41bbf18b27562c61b71612e6e3\n> filename: lib/views/html/shared/_standardOptions.php\n> Checking lib/views/html/shared/_standardOptions.php\n> mode: 100644 type: blob blob: 3f9c8db23f4517fa0aff311b6036324dbbf1547e\n> filename: lib/views/html/shared/_validationErrors.php\n> Checking lib/views/html/shared/_validationErrors.php\n> mode: 100755 type: blob blob: 0ed20cbaa2ebefc6b473ef19e2f0534916fe8401\n> filename: scripts/clean_sandbox.sh\n> mode: 100755 type: blob blob: 3460ac158ec6e49d18947659a88f89fee6742005\n> filename: scripts/client_atomicity_cutover.sh\n> mode: 100755 type: blob blob: 605fe7efe119e13e608010c500e8d46a9aa78678\n> filename: scripts/consolidate-links.py\n> mode: 100755 type: blob blob: 937fd93c9dec4ccbd097a0c738308e294555e074\n> filename: scripts/cutover_client.sh\n> mode: 100755 type: blob blob: 8de04dd40f433abc83e55694c0b18fe8e8a4be5f\n> filename: scripts/mk_client_repos.sh\n> mode: 100755 type: blob blob: 683e36ed7736d8dafaff73ddc25d8eceb2184ff7\n> filename: scripts/new_client_setup.sh\n> mode: 100755 type: blob blob: 50215aad6a97654524a19cec45863c22f75338de\n> filename: scripts/push_branch.sh\n> mode: 100755 type: blob blob: b562aef0d6184919a1867d38d884cec8b5d0b8cb\n> filename: scripts/release/create-migrations.sh\n> mode: 100755 type: blob blob: 85161b45e9cda0d9c11ae855ebe7f9352fef624a\n> filename: scripts/release/deploy-mailer-compat.sh\n> mode: 100755 type: blob blob: c3d147d2129320941d9ffba072f29378fae6f6f2\n> filename: scripts/release/find-merged-branches.sh\n> mode: 100755 type: blob blob: 81e81767bb05fa037598e308e4870f08fff8314e\n> filename: scripts/release/mailer-compat.sh\n> mode: 100755 type: blob blob: 84db6a40b1aaefe87d62f06a86f566041563e6a5\n> filename: scripts/release/tag-deploy-config.sh\n> mode: 100755 type: blob blob: 5a359fff5e6c0590c3bcea43b16420217f50a285\n> filename: scripts/release/tag-release.sh\n> mode: 100755 type: blob blob: ce1256c79a87e7d6e34f6d8dd539e6cb7187d595\n> filename: scripts/remove_cvs_dirs.sh\n> mode: 100755 type: blob blob: f2941728666e41d44c0a90b1f3640920de3bb99f\n> filename: scripts/remove_cvs_dirs_group.sh\n> mode: 100755 type: blob blob: 0a1a3e1cc43f693f941405030318d0ee55379d5b\n> filename: scripts/remove_cvs_dirs_server.sh\n> mode: 100755 type: blob blob: 52d399655cba3f4dbf6b052a44626cad2136d9a2\n> filename: scripts/remove_scratch_dirs.sh\n> mode: 100755 type: blob blob: 5cb2eed1bb0ce1e3f59f5e0bba2f39cf1578b433\n> filename: scripts/shared_resources_client_update.sh\n> mode: 100755 type: blob blob: f6fd4a715ff2165e58e7ae469b7f2beffd10683e\n> filename: scripts/show_cv.sh\n> mode: 100755 type: blob blob: 2c6fdbff1cc764d17162f4c926ac19c5e7a3771e\n> filename: scripts/show_cv_json.sh\n> mode: 100644 type: blob blob: 0d1fa845d2d1cfc068df2c3d91408b1ff8ea428f\n> filename: test/.gitignore\n> mode: 100644 type: blob blob: c8a970f86b3279c824e750304ae7dcd1c671f9ef\n> filename: test/BlueTestCase.php\n> Checking test/BlueTestCase.php\n> mode: 100644 type: blob blob: a46ad98c60b25e344e35a7ece5581ed8da8ba37b\n> filename: test/BlueTestSuite.php\n> Checking test/BlueTestSuite.php\n> mode: 100644 type: blob blob: d649763699177b566c060471eba98ef0d6b60934\n> filename: test/CommandExposer.php\n> Checking test/CommandExposer.php\n> mode: 100755 type: blob blob: 14740e1d5b8110d4bd61a01b46f2dd55a030016b\n> filename: test/bsdunit\n> mode: 100644 type: blob blob: 8c4c794ff20baf349c966a03a5d78e1ae0151b31\n> filename: test/fixtures/ClientConfigFixtures.php\n> Checking test/fixtures/ClientConfigFixtures.php\n> mode: 100644 type: blob blob: a3a3c4b4a349ac8d322187b3e638cc8b7c4a853f\n> filename: test/morebogus.php\n> Checking test/morebogus.php\n> There was a syntax error in 'test/morebogus.php'.  Rejecting this\n> attempted merge!\n> error: hooks/pre-receive exited with error code 1\n> To ssh://git.bluestatedigital.com/home/git/bsdrelease\n>  ! [remote rejected] bug-28046 -> bug-28046 (pre-receive hook declined)\n> error: failed to push some refs to\n> 'ssh://git.bluestatedigital.com/home/git/bsdrelease'\n> [17:01][admin@Chris-Patti:~/src/bsdrelease/test(bug-28046)]$\n> \n> Why is git ls-tree returning all those blobs that are totally\n> unrelated to my check-in, and how can I constrain the files I'm syntax\n> checking to only those in the current commit?\n\n...because \"ls-tree\" lists the complete tree at the given revision, not\njust the files changed in a commit. In fact, strictly speaking \"ls-tree\"\ndoes not even operate on revisions but tree identifiers - given a\nrevision, it is resolved into a tree.\n\nYou want to use something like \"git diff --name-only oldrev newrev\" or\nanother variant from the diff family.\n\nMichael\n"},{"id":"149320","messageId":"AANLkTimqzDO49h40b16gQ_=X42NXN-wZNV7d7f3KYygt@mail.gmail.com","threadId":"24891","inReplyTo":"4C7B8E1E.6050708@drmicha.warpmail.net","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-30T14:03:15Z","receivedAt":"2010-08-30T14:03:15Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 6:55 AM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n>\n> ...because \"ls-tree\" lists the complete tree at the given revision, not\n> just the files changed in a commit. In fact, strictly speaking \"ls-tree\"\n> does not even operate on revisions but tree identifiers - given a\n> revision, it is resolved into a tree.\n>\n> You want to use something like \"git diff --name-only oldrev newrev\" or\n> another variant from the diff family.\n>\n> Michael\n\nThat's great, thanks!  That gets me the file names.  Now, how do I get\nto the contents of each file?\n\nDo I have to do a git ls-tree and parse the contents, paying attention\nto only the files listed out with the git diff --name-only? I'm\nguessing there's a simpler way.   Git show <newref> prints out all the\ndiffs for that commit, but I need to examine the entire file.\n\nThanks so much for the response!\n-Chris\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149324","messageId":"20100830141602.GF2315@burratino","threadId":"24891","inReplyTo":"AANLkTimqzDO49h40b16gQ_=X42NXN-wZNV7d7f3KYygt@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-30T14:16:02Z","receivedAt":"2010-08-30T14:16:02Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Chris Patti wrote:\n\n> That's great, thanks!  That gets me the file names.  Now, how do I get\n> to the contents of each file?\n\nWhy not \"git diff --raw\" (or its plumbing equivalent \"git diff-tree\")?\n"},{"id":"149327","messageId":"AANLkTi=GUrnH87faWH8G0tD7_KAynVf_ig0KpQRwnsaE@mail.gmail.com","threadId":"24891","inReplyTo":"20100830141602.GF2315@burratino","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-30T14:24:18Z","receivedAt":"2010-08-30T14:24:18Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 10:16 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Chris Patti wrote:\n>\n>> That's great, thanks!  That gets me the file names.  Now, how do I get\n>> to the contents of each file?\n>\n> Why not \"git diff --raw\" (or its plumbing equivalent \"git diff-tree\")?\n>\n\nThat is absolutely *perfect* sir, thank you very much! That gets me\nthe blobs I can 'git show' as well as the filenames so I can cherry\npick only PHP files to check.\n\n-Chris\n(P.S. Is there a canonical 'example Git hooks' location I could\npublish this to when it's working? I think there's a dearth of this\nkind of example for people out there right now)\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149328","messageId":"4C7BC068.7030909@drmicha.warpmail.net","threadId":"24891","inReplyTo":"20100830141602.GF2315@burratino","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-08-30T14:30:00Z","receivedAt":"2010-08-30T14:30:00Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jonathan Nieder venit, vidit, dixit 30.08.2010 16:16:\n> Chris Patti wrote:\n> \n>> That's great, thanks!  That gets me the file names.  Now, how do I get\n>> to the contents of each file?\n> \n> Why not \"git diff --raw\" (or its plumbing equivalent \"git diff-tree\")?\n\nThat's what I meant by \"diff family\" ;)\nIn fact, \"git diff --raw --name-only oldrev newrev\" gives the nicest\nlisting.\n\nIt seems Chris has to check full file contents, i.e. he'll have to loop\nover this list (as before), but I guess he'll need to replace his \"show\n$blob\" by \"show newrev:$filename\" (or, alternatively, parse the output\nof \"diff --raw\" without \"--name-only\" for the blob sha1).\n\nMichael\n"},{"id":"149331","messageId":"20100830143411.GH2315@burratino","threadId":"24891","inReplyTo":"AANLkTi=GUrnH87faWH8G0tD7_KAynVf_ig0KpQRwnsaE@mail.gmail.com","subject":"Example git hooks (Re: Odd results writing a Git pre-receive hook to syntax check PHP files.)","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-30T14:34:11Z","receivedAt":"2010-08-30T14:34:11Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Chris Patti wrote:\n\n> (P.S. Is there a canonical 'example Git hooks' location I could\n> publish this to when it's working? I think there's a dearth of this\n> kind of example for people out there right now)\n\nTry the git wiki (git.wiki.kernel.org).  There is a page for aliases\nbut no page for example hooks yet (though there are some examples\nunder InterfacesFrontendsAndTools).  You could be the trailblazer.\n\nThere are also a few examples in git templates/ and contrib/hooks,\nof course.\n"},{"id":"149335","messageId":"AANLkTimFx0DQb0Bq=00O5jSwbFpxU6TE53fMoiJd4Rdy@mail.gmail.com","threadId":"24891","inReplyTo":"4C7BC068.7030909@drmicha.warpmail.net","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-30T15:00:23Z","receivedAt":"2010-08-30T15:00:23Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 10:30 AM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n> Jonathan Nieder venit, vidit, dixit 30.08.2010 16:16:\n>> Chris Patti wrote:\n>>\n>>> That's great, thanks!  That gets me the file names.  Now, how do I get\n>>> to the contents of each file?\n>>\n>> Why not \"git diff --raw\" (or its plumbing equivalent \"git diff-tree\")?\n>\n> That's what I meant by \"diff family\" ;)\n> In fact, \"git diff --raw --name-only oldrev newrev\" gives the nicest\n> listing.\n>\n> It seems Chris has to check full file contents, i.e. he'll have to loop\n> over this list (as before), but I guess he'll need to replace his \"show\n> $blob\" by \"show newrev:$filename\" (or, alternatively, parse the output\n> of \"diff --raw\" without \"--name-only\" for the blob sha1).\n>\n> Michael\n>\n\nExactly, I'm writing a regex to parse the diff --raw output and\nextract the needed bits.  I was already doing this with ls-tree so I\ndon't expect any difficulties.\n\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149343","messageId":"AANLkTim+S87KjFBstBineR02hQHzG=X2VDqgiGNbPQGS@mail.gmail.com","threadId":"24891","inReplyTo":"20100830141602.GF2315@burratino","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-30T16:27:22Z","receivedAt":"2010-08-30T16:27:22Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 10:16 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Chris Patti wrote:\n>\n>> That's great, thanks!  That gets me the file names.  Now, how do I get\n>> to the contents of each file?\n>\n> Why not \"git diff --raw\" (or its plumbing equivalent \"git diff-tree\")?\n>\n\nOK, went down this path and hit a brick wall.  What if this is the\nfirst time a new ref is being pushed?  Then, old-ref is 000000 and git\ndiff --raw throws up a hairball :)\n---\n[12:23][cpatti@build1:~/src/relengtest(test-branch)]$ git push origin\ntest-branch\nCounting objects: 10, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (7/7), done.\nWriting objects: 100% (7/7), 684 bytes, done.\nTotal 7 (delta 1), reused 0 (delta 0)\nUnpacking objects: 100% (7/7), done.\nns: 9f75c41fe7ec26ddf318929d62ebb26f3c1d3d0c\nos: 0000000000000000000000000000000000000000\nrefname: refs/heads/test-branch\n\nfatal: bad object 0000000000000000000000000000000000000000\nSyntax checker hook is malfunctioning.  Can't execute git diff --raw.\nFailing gracefully and allowing this push.\nTo /home/git/relengtest\n * [new branch]      test-branch -> test-branch\n\nAny further thoughts?\n\nThanks!\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149344","messageId":"AANLkTimX4qFubV68=_0kmPpq89cafH9acqzcshSMdVVe@mail.gmail.com","threadId":"24891","inReplyTo":"AANLkTim+S87KjFBstBineR02hQHzG=X2VDqgiGNbPQGS@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-08-30T16:32:40Z","receivedAt":"2010-08-30T16:32:40Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, Aug 30, 2010 at 11:27, Chris Patti <cpatti@gmail.com> wrote:\n> fatal: bad object 0000000000000000000000000000000000000000\n> Syntax checker hook is malfunctioning.  Can't execute git diff --raw.\n\nCheck before calling 'git diff --raw' if the lhs is\n0000000000000000000000000000000000000000 or not, if it is, just use\ngit show on all files?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"149345","messageId":"20100830163302.GA13336@burratino","threadId":"24891","inReplyTo":"AANLkTim+S87KjFBstBineR02hQHzG=X2VDqgiGNbPQGS@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-30T16:33:02Z","receivedAt":"2010-08-30T16:33:02Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Chris Patti wrote:\n\n> What if this is the\n> first time a new ref is being pushed?  Then, old-ref is 000000 and git\n> diff --raw throws up a hairball :)\n\nCan't you check for 0{40} and use $(git hash-object -t tree </dev/null)\nin its place?\n\nIn general, the \"LOW-LEVEL COMMANDS (PLUMBING)\" listed on the git man\npage are meant to be useful for scripts.  They have simple input and\noutput formats, they don't try to introduce weird exceptions for user\nconvenience, the git developers are more conservative about changing\nthem, and so on.\n"},{"id":"149349","messageId":"AANLkTi=VPf9CWNJcce6d20HQChi0mHgTG1F=jakzNT-O@mail.gmail.com","threadId":"24891","inReplyTo":"20100830163302.GA13336@burratino","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-30T17:37:27Z","receivedAt":"2010-08-30T17:37:27Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 12:33 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Chris Patti wrote:\n>\n>> What if this is the\n>> first time a new ref is being pushed?  Then, old-ref is 000000 and git\n>> diff --raw throws up a hairball :)\n>\n> Can't you check for 0{40} and use $(git hash-object -t tree </dev/null)\n> in its place?\n>\n> In general, the \"LOW-LEVEL COMMANDS (PLUMBING)\" listed on the git man\n> page are meant to be useful for scripts.  They have simple input and\n> output formats, they don't try to introduce weird exceptions for user\n> convenience, the git developers are more conservative about changing\n> them, and so on.\n>\n\nMaybe I'm not understanding your intent here, but, this is a\npre-receive hook, where you get handed two refs, the old (pre-push)\nref, and the new (after push) ref.\n\ngit hash-object computes a hash from the file's contents.  That's my\nwhole point, I don't *have* the file to compute! All I have is those\ntwo refs.\n\nThanks,\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149355","messageId":"4C7C020C.6090907@drmicha.warpmail.net","threadId":"24891","inReplyTo":"AANLkTi=VPf9CWNJcce6d20HQChi0mHgTG1F=jakzNT-O@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-08-30T19:10:04Z","receivedAt":"2010-08-30T19:10:04Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Chris Patti venit, vidit, dixit 30.08.2010 19:37:\n> On Mon, Aug 30, 2010 at 12:33 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>> Chris Patti wrote:\n>>\n>>> What if this is the\n>>> first time a new ref is being pushed?  Then, old-ref is 000000 and git\n>>> diff --raw throws up a hairball :)\n>>\n>> Can't you check for 0{40} and use $(git hash-object -t tree </dev/null)\n>> in its place?\n>>\n>> In general, the \"LOW-LEVEL COMMANDS (PLUMBING)\" listed on the git man\n>> page are meant to be useful for scripts.  They have simple input and\n>> output formats, they don't try to introduce weird exceptions for user\n>> convenience, the git developers are more conservative about changing\n>> them, and so on.\n>>\n\ngit diff-tree --root $newrev\n\nwill take care of this.\n\n> \n> Maybe I'm not understanding your intent here, but, this is a\n> pre-receive hook, where you get handed two refs, the old (pre-push)\n> ref, and the new (after push) ref.\n> \n> git hash-object computes a hash from the file's contents.  That's my\n> whole point, I don't *have* the file to compute! All I have is those\n> two refs.\n\nYou do have the files, otherwise you couldn't check them. They're in\nyour git file system ;)\n\nMichael\n"},{"id":"149392","messageId":"20100831015712.GT4925@inocybe.localdomain","threadId":"24891","inReplyTo":"20100830143411.GH2315@burratino","subject":"Re: Example git hooks (Re: Odd results writing a Git pre-receive hook to syntax check PHP files.)","fromName":"Todd Zullinger","fromEmail":"tmz@pobox.com","sentAt":"2010-08-31T01:57:12Z","receivedAt":"2010-08-31T01:57:12Z","isPatch":false,"sender":{"key":"tmz@pobox.com","avatar":"https://avatars.githubusercontent.com/u/806319?v=4"},"body":"Jonathan Nieder wrote:\n> Chris Patti wrote:\n>\n>> (P.S. Is there a canonical 'example Git hooks' location I could\n>> publish this to when it's working? I think there's a dearth of this\n>> kind of example for people out there right now)\n>\n> Try the git wiki (git.wiki.kernel.org).  There is a page for aliases\n> but no page for example hooks yet (though there are some examples\n> under InterfacesFrontendsAndTools).  You could be the trailblazer.\n>\n> There are also a few examples in git templates/ and contrib/hooks,\n> of course.\n\nThis reminds me a little of a discussion that came up a while back\nregarding syntax checking of puppet manifests.  The resulting hook is\nhere:\n\nhttp://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Version_Control#Git+Update+Hook\n\nThe git list discussion:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/118626\n\nDunno if that'll help you at all or not Chris.  Hopefully it doesn't\nhurt at least. :)\n\n-- \nTodd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nEvery side I get up on is the wrong side of bed.\nIf it weren't so expensive, I'd wish I were dead.\n    -- signed Unhappy\n\n"},{"id":"149413","messageId":"AANLkTin8ZB8phz9J0TQwNoC4t4TZYz5PKW=yrhiV7i+1@mail.gmail.com","threadId":"24891","inReplyTo":"20100831015712.GT4925@inocybe.localdomain","subject":"Re: Example git hooks (Re: Odd results writing a Git pre-receive hook to syntax check PHP files.)","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-31T13:11:10Z","receivedAt":"2010-08-31T13:11:10Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 9:57 PM, Todd Zullinger <tmz@pobox.com> wrote:\n> Jonathan Nieder wrote:\n>> Chris Patti wrote:\n>>\n>>> (P.S. Is there a canonical 'example Git hooks' location I could\n>>> publish this to when it's working? I think there's a dearth of this\n>>> kind of example for people out there right now)\n>>\n>> Try the git wiki (git.wiki.kernel.org).  There is a page for aliases\n>> but no page for example hooks yet (though there are some examples\n>> under InterfacesFrontendsAndTools).  You could be the trailblazer.\n>>\n>> There are also a few examples in git templates/ and contrib/hooks,\n>> of course.\n>\n> This reminds me a little of a discussion that came up a while back\n> regarding syntax checking of puppet manifests.  The resulting hook is\n> here:\n>\n> http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Version_Control#Git+Update+Hook\n>\n> The git list discussion:\n>\n> http://thread.gmane.org/gmane.comp.version-control.git/118626\n>\n> Dunno if that'll help you at all or not Chris.  Hopefully it doesn't\n> hurt at least. :)\n>\n> --\n> Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp\n> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n> Every side I get up on is the wrong side of bed.\n> If it weren't so expensive, I'd wish I were dead.\n>    -- signed Unhappy\n>\n>\n\nAn interesting example, thanks for that!\n\nWhat's interesting is that it also evidences another characteristic I\nsaw in a hook someone wrote here - they treat old_sha1 being 000000000\nas a deletion, but I'm also seeing that when the hook is invoked on\nthe first push in a new branch (Which makes sense since there is no\nold_sha1) but it makes me wonder if people are unaware of an implicit\nbug - in this case, all such pushes are skipped and not checked, so\nthis means that someone can check in broken Puppet code if they are\nthe first ones to do so on a new branch.\n\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149497","messageId":"AANLkTimiSBjifxtDoFXAEAEpYM8bJ18SwJ5Fj8zqh_G6@mail.gmail.com","threadId":"24891","inReplyTo":"4C7C020C.6090907@drmicha.warpmail.net","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-31T21:06:50Z","receivedAt":"2010-08-31T21:06:50Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 3:10 PM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n>\n> git diff-tree --root $newrev\n>\n> will take care of this.\n>\n> Michael\n>\n\nThank you sir! You are a scholar and a gentleman, and I sincerely\nappreciate the help.\n\nHere is the completed hook for anyone who is curious, this turned into\na more complex project than I thought it would be, but I learned a\nheck of a lot along the way so that's a good thing!\n\n-Chris\n----\n#!/home/php/bin/php\n<?php\n\nfunction parseHookInput() {\n        $fpstdin = fopen(\"php://stdin\",\"r\");\n\n        $line = fgets($fpstdin);\n\n        list($old_sha1,$new_sha1,$refname)=explode(\" \",$line);\n\n        #echo \"ns: $new_sha1\\n\";\n        #echo \"os: $old_sha1\\n\";\n        #echo \"refname: $refname\\n\";\n        return array($old_sha1,$new_sha1);\n}\n\nfunction detectNewBranch($old_sha1,$new_sha1) {\n        if ($old_sha1 == \"0000000000000000000000000000000000000000\") {\n                return true;\n        }\n        else {\n                return false;\n        }\n}\n\n\nfunction parseDiff($old_sha1,$new_sha1,$diffcmd,$regex) {\n        $diff = array();\n\n        exec($diffcmd,$diff,$diffrcval);\n        if ($diffrcval != 0) {\n                echo \"Syntax checker hook is malfunctioning.  Can't\nexecute git ls-tree.  Failing gracefully and allowing this push.\\n\";\n                exit(0);\n        }\n        # If we can execute the git diff I'm assuming we have access\nto a working git.\n\n        foreach ($diff as &$diffline) {\n                preg_match($regex,$diffline,$matches);\n                $blob = $matches[1];\n                $filename = $matches[2];\n                #echo \"Blob: $blob Filename: $filename\\n\";\n                SyntaxCheckFile($blob,$filename);\n        }\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\nfunction parseCommit($old_sha1,$new_sha1) {\n        # if this is the first commit on a new branch, $old_sha1 will\nbe a bunch of zeroes, and so\n        # git diff --raw will fail, since there's no old ref to\ncompare against.  So, we parse the\n        # results of git diff-tree -root=$new_sha1 instead to get the\nblob and filename we'll need.\n        if (detectNewBranch($old_sha1,$new_sha1)) {\n                $diffcmd=\"git diff-tree --root $new_sha1\";\n                $regex=\"/\\:\\w+ \\w+ \\w+ (\\w+) \\w (.+)/\";\n        }\n        else {\n                $diffcmd=\"git diff --raw $old_sha1 $new_sha1\";\n                $regex=\"/\\:\\d+ \\d+ \\w+... (\\w+)... \\w\\t(.+)/\";\n        }\n        parseDiff($old_sha1,$new_sha1,$diffcmd,$regex);\n}\n\n# End function definitions.  Main code body starts here.\n\n# This pre-receive git hook gets passed the ref before the push, and\nthe ref that would be\n# created if the push succeeds.\nlist($old_sha1,$new_sha1) = parseHookInput();\n\nparseCommit($old_sha1,$new_sha1);\n\nexit(0);\n\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149498","messageId":"AANLkTi=8GQrF_4r44FscA8xCVRnXG-J4cO3fW07WTmL+@mail.gmail.com","threadId":"24891","inReplyTo":"20100830143411.GH2315@burratino","subject":"Re: Example git hooks (Re: Odd results writing a Git pre-receive hook to syntax check PHP files.)","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-08-31T21:14:57Z","receivedAt":"2010-08-31T21:14:57Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Mon, Aug 30, 2010 at 10:34 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Chris Patti wrote:\n>\n>> (P.S. Is there a canonical 'example Git hooks' location I could\n>> publish this to when it's working? I think there's a dearth of this\n>> kind of example for people out there right now)\n>\n> Try the git wiki (git.wiki.kernel.org).  There is a page for aliases\n> but no page for example hooks yet (though there are some examples\n> under InterfacesFrontendsAndTools).  You could be the trailblazer.\n>\n> There are also a few examples in git templates/ and contrib/hooks,\n> of course.\n>\n\nThis is sub optimal.  We really need a central Git repo somewhere\nwhere people can just contribute the hooks they've written.\n\nI can certainly create a new page for my hook and paste the code in,\nbut all the hooks that are currently up there are links to hooks\nhosted elsewhere, and I would rather not provide pointers to my\npersonal domain/hosting because that could change without notice.\n\nHrrm.\n\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149512","messageId":"7vk4n68hpk.fsf@alter.siamese.dyndns.org","threadId":"24891","inReplyTo":"AANLkTimiSBjifxtDoFXAEAEpYM8bJ18SwJ5Fj8zqh_G6@mail.gmail.com","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-31T23:50:47Z","receivedAt":"2010-08-31T23:50:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Patti <cpatti@gmail.com> writes:\n\n> function parseCommit($old_sha1,$new_sha1) {\n>         # if this is the first commit on a new branch, $old_sha1 will\n> be a bunch of zeroes, and so\n>         # git diff --raw will fail, since there's no old ref to\n> compare against.  So, we parse the\n>         # results of git diff-tree -root=$new_sha1 instead to get the\n> blob and filename we'll need.\n>         if (detectNewBranch($old_sha1,$new_sha1)) {\n>                 $diffcmd=\"git diff-tree --root $new_sha1\";\n\nThis somehow feels wrong.  If the tree of the new commit is flat without\nsubdirectory, the above would do, but don't you need \"diff-tree -r\" here?\n\n>                 $regex=\"/\\:\\w+ \\w+ \\w+ (\\w+) \\w (.+)/\";\n>         }\n>         else {\n>                 $diffcmd=\"git diff --raw $old_sha1 $new_sha1\";\n\nAnd you are better off using \"diff-tree -r\" here instead of \"diff --raw\"\nhere as well, to keep the input to your parser for both cases uniform.\nThe parser would be easier that way, no?\n\n>                 $regex=\"/\\:\\d+ \\d+ \\w+... (\\w+)... \\w\\t(.+)/\";\n>         }\n"},{"id":"149557","messageId":"AANLkTi=GP-3QV+2cVUV1zCS_n2gPie_rBmBnbXgmmbgn@mail.gmail.com","threadId":"24891","inReplyTo":"7vk4n68hpk.fsf@alter.siamese.dyndns.org","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-09-01T13:43:23Z","receivedAt":"2010-09-01T13:43:23Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Tue, Aug 31, 2010 at 7:50 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Chris Patti <cpatti@gmail.com> writes:\n>\n>> function parseCommit($old_sha1,$new_sha1) {\n>>         # if this is the first commit on a new branch, $old_sha1 will\n>> be a bunch of zeroes, and so\n>>         # git diff --raw will fail, since there's no old ref to\n>> compare against.  So, we parse the\n>>         # results of git diff-tree -root=$new_sha1 instead to get the\n>> blob and filename we'll need.\n>>         if (detectNewBranch($old_sha1,$new_sha1)) {\n>>                 $diffcmd=\"git diff-tree --root $new_sha1\";\n>\n> This somehow feels wrong.  If the tree of the new commit is flat without\n> subdirectory, the above would do, but don't you need \"diff-tree -r\" here?\n>\n\nThat's a good point, I'll try creating a subdirectory in my testing,\nthanks for pointing this out.\n\n>>                 $regex=\"/\\:\\w+ \\w+ \\w+ (\\w+) \\w (.+)/\";\n>>         }\n>>         else {\n>>                 $diffcmd=\"git diff --raw $old_sha1 $new_sha1\";\n>\n> And you are better off using \"diff-tree -r\" here instead of \"diff --raw\"\n> here as well, to keep the input to your parser for both cases uniform.\nr> The parser would be easier that way, no?\n>\n>>                 $regex=\"/\\:\\d+ \\d+ \\w+... (\\w+)... \\w\\t(.+)/\";\n>>         }\n>\n\n\nAs you can see, it's just the regex that differs, so I'm not sure what\nyou mean by 'parser'.  The power of regular expressions handles this\nquite nicely, but I'll definitely consider that for a simplifying\nrewrite in the future.\n\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"},{"id":"149643","messageId":"AANLkTiks+y8edtpkbu+t=22rct_KXv9aOHaG88-MWapK@mail.gmail.com","threadId":"24891","inReplyTo":"7vk4n68hpk.fsf@alter.siamese.dyndns.org","subject":"Re: Odd results writing a Git pre-receive hook to syntax check PHP files.","fromName":"Chris Patti","fromEmail":"cpatti@gmail.com","sentAt":"2010-09-02T14:34:18Z","receivedAt":"2010-09-02T14:34:18Z","isPatch":false,"sender":{"key":"cpatti@gmail.com","avatar":null},"body":"On Tue, Aug 31, 2010 at 7:50 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Chris Patti <cpatti@gmail.com> writes:\n>\n>> function parseCommit($old_sha1,$new_sha1) {\n>>         # if this is the first commit on a new branch, $old_sha1 will\n>> be a bunch of zeroes, and so\n>>         # git diff --raw will fail, since there's no old ref to\n>> compare against.  So, we parse the\n>>         # results of git diff-tree -root=$new_sha1 instead to get the\n>> blob and filename we'll need.\n>>         if (detectNewBranch($old_sha1,$new_sha1)) {\n>>                 $diffcmd=\"git diff-tree --root $new_sha1\";\n>\n> This somehow feels wrong.  If the tree of the new commit is flat without\n> subdirectory, the above would do, but don't you need \"diff-tree -r\" here?\n>\n\nI tested with subdirectories, and subdirs with subdirs, and no\nfailures, worked perfectly.  So, not sure what feels wrong to you, but\nfor now, it works :) I will seek to better understand the internals\nI'm mucking with here so I can figure out why you see the current\nimplementation as being suspect.\n\n-Chris\n\n\n-- \nChristopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:\nchrisfeohpatti | P: (260) 54PATTI\n\"Technology challenges art, art inspires technology.\" - John Lasseter, Pixar\n"}]}