簡體   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