Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git pre-commit takes no params #5107

Closed
kenjis opened this issue Sep 20, 2021 · 2 comments · Fixed by #5116
Closed

Git pre-commit takes no params #5107

kenjis opened this issue Sep 20, 2021 · 2 comments · Fixed by #5116

Comments

@kenjis
Copy link
Member

kenjis commented Sep 20, 2021

There is code in pre-commit:

# Determine if a file list is passed
if [ "$#" -eq 1 ]; then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi

But it seems it makes no sense.

To check, I added the following code:

--- pre-commit.orig     2021-09-20 09:33:38.000000000 +0900
+++ pre-commit  2021-09-20 09:36:17.000000000 +0900
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "$@"; exit 1
+
 PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
 STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php$`
 

And run git commit:

$ git commit

$ git commit -- user_guide_src/ghpages.rst

$ 

And I found the docs:

pre-commit

This hook is invoked by git-commit[1], and can be bypassed with the --no-verify option. It takes no parameters, and is invoked before obtaining the proposed commit log message and making a commit. E
https://git-scm.com/docs/githooks

@paulbalandan
Copy link
Member

This one is copied over from the same file in cakephp, I think. That part I think is to manually test the script before being deployed as a git hook. Something like:

$ bash admin/pre-commit file1.php file2.php

@kenjis
Copy link
Member Author

kenjis commented Sep 21, 2021

It is from https://tech.zumba.com/2014/04/14/control-code-quality/ ?

That part I think is to manually test the script before being deployed as a git hook.

Maybe. But it uses only $1. Like this?

$ bash admin/pre-commit "file1.php file2.php"

In any case, it's code that is difficult to understand.

kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Sep 23, 2021
paulbalandan pushed a commit that referenced this issue Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants