繁体   English   中英

Git hook没有运行2个连续命令

[英]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 ...

看看exec联机帮助页

如果指定了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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM