简体   繁体   中英

Git hook not running 2 consecutive commands

I'm trying to create a pre-push hook to run php-cs-fixer before every push.

This is the current pre-push hook I have:

#!/bin/sh

exec php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2'

The first command gets trigger without a problem. Only the git commit -am 'PSR-2 doesn't. To be more precise, the php-cs-fixer runs followed by this error error: failed to push some refs to ..

I also tried the following without luck:

#!/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')

According to this stackoverflow question, it should run only if cmd1 has succeeded.

The exec builtin command replaces the shell with the given program. It does NOT fork a new process to execute php-cs-fixer .

Since the shell is replaced by the php-cs-fixer program the && git commit ... is never executed.

Take a look at the manpage of exec

If command is specified, it replaces the shell. No new process is created.

The first line of php-cs-fixer should look like this

#!/usr/bin/env php

and the php-cs-fixer should have execute permissions chmod +x php-cs-fixer .

Than you can just use it

php-cs-fixer fix . --config-file=".php_cs" && git commit -am 'PSR-2'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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