[英]Git hook not running 2 consecutive commands
我正在尝试创建一个pre-push
钩,以便在每次推送之前运行php-cs-fixer
。
这是我目前的pre-push
钩:
#!/bin/sh
exec php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2'
第一个命令没有问题就触发了。 只有git commit -am 'PSR-2
没有。 更确切地说, php-cs-fixer
运行后出现此错误error: failed to push some refs to ..
没有运气我也尝试了以下内容:
#!/bin/sh
php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2'
-
#!/bin/sh
(php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2')
根据这个stackoverflow问题,它应该只在cmd1成功时运行。
exec
builtin命令用给定的程序替换shell。 它没有一个新的进程来执行php-cs-fixer
。
由于shell被php-cs-fixer
程序取代,因此永远不会执行&& git commit ...
如果指定了command,则替换shell。 没有创建新进程。
php-cs-fixer
的第一行应该是这样的
#!/usr/bin/env php
并且php-cs-fixer
应该具有执行权限chmod +x php-cs-fixer
。
比你可以使用它
php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.