hooks4git icon indicating copy to clipboard operation
hooks4git copied to clipboard

Hook wrappers do not pass on hook parameters given by git

Open chfr opened this issue 3 years ago • 2 comments

Hi! For some hooks (for example commit-msg), git will call the hook with the path to the file containing the commit message (almost always .git/COMMIT_EDITMSG). From man githooks:

   commit-msg
       This hook is invoked by git commit, and can be bypassed with the --no-verify option. 
       It takes a single parameter, the name of the file that holds the proposed commit log message.

However, the hooks4git wrappers discard these parameters:

$ cat .git/hooks/commit-msg
#!/bin/bash
if [ -x "$(command -v hooks4git)" ]; then
    hooks4git -t $(basename $0)
fi

Is there a reason that hooks4git cannot pass these parameters on to the hooks? I tried adding "$@" to the end of the hooks4git command but that obviously didn't work out of the box :) Thanks!

chfr avatar Aug 10 '20 13:08 chfr

Sorry not seeing that before. Let me look into it.

lovato avatar Dec 14 '20 07:12 lovato

Well, the $(basename $0) is just to get the name of the hook being triggered, so I can forward that information to inside H4G. $0 is the calling script name inside your project .git hooks folder.

Not sure if I fully got it, but can you explain what are you trying to get solved? This piece of code does what it needs to do. The git operation happens, a hook is called, I intercept that and propagate that into hooks4git logic, it runs the analysis, and provides a 0 or 1 back to git caller executable. Then, and only then, git workflow actually finalizes, outside hooks4git logic.

lovato avatar Dec 14 '20 19:12 lovato