Closed ruslan-y closed 3 months ago
Hm... weird case. I mean you are using #!/bin/sh
which is POSIX shell but should also work because what you do in your hook is ( afaik) compliant with sh
. Can you check if the file is made chmod +x
and maybe change to #! /usr/bin/env bash
which is far more robust. Somehow its not finding cat
which is weird. Maybe you can print the env variables with env
and check what it contains? Please report that here.
Another note: You can make this hook containerized if you like (check the examples) such that it runs with docker
or podman
, I am however a bit unsure how the $1
will work, because the path in the container might be different. I think the containerized version of prepare-commit-msg
might have some troubles I need to fix or provide a decent workaround =).
Another note: Always use set -u
and set -e
(every non-zero exit is an error and a direct exit) in shell scripts.
Hi! I've completed everything that you described above but it didn't help.
file execution right is correct
-rwxr-xr-x 1 user staff 728B Jun 5 11:31 prepare-commit-msg
Also i've tried used #! /usr/bin/env bash
into the script. The same problem.
I'v added env
command into the script before main part
SHELL=/bin/zsh
LSCOLORS=Gxfxcxdxbxegedabagacad
ITERM_PROFILE=Default
COLORTERM=truecolor
LESS=-R
XPC_FLAGS=0x0
TERM_PROGRAM_VERSION=3.5.0
TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
__CFBundleIdentifier=com.googlecode.iterm2
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.4Fka7gWzlc/Listeners
GITHOOKS_ARCH=arm64
GIT_INDEX_FILE=.git/index
PWD=/Users/user/Projects/1/test-hooks123
LOGNAME=user
GIT_AUTHOR_DATE=@1717570624 +0500
COMMAND_MODE=unix2003
GIT_EXEC_PATH=/opt/homebrew/opt/git/libexec/git-core
HOME=/Users/user
LANG=ru_RU.UTF-8
TMPDIR=/var/folders/qx/zlx7pbzj5nsfv7kv7lq1s99c0000gn/T/
LC_TERMINAL=iTerm2
GIT_AUTHOR_EMAIL=email
GIT_PREFIX=
STAGED_FILES=0958
TERM=xterm-256color
ZSH=/Users/user/.oh-my-zsh
USER=user
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
COLORFGBG=15;0
LC_TERMINAL_VERSION=3.5.0
SHLVL=2
GITHOOKS_OS=darwin
GIT_EDITOR=:
PAGER=less
XPC_SERVICE_NAME=0
TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
LC_ALL=en_US.UTF-8
GIT_AUTHOR_NAME=User User
PATH=/opt/homebrew/opt/git/libexec/git-core:/opt/homebrew/opt/git/libexec/git-core:/opt/homebrew/bin:/opt/homebrew/opt/node@18/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/iTerm.app/Contents/Resources/utilities:/opt/homebrew/bin/
__CF_USER_TEXT_ENCODING=0x1F5:0x7:0x31
TERM_PROGRAM=iTerm.app
_=/usr/bin/env
I will investigate this: It seems that indeed something is fishy here. I write a short test case quicky.
BTW: Never ever share the env
without deleting some strange TOKEN env variables nobody should see, I update your message above.
In the meantime: Can you add echo "Args:" "$@"
at the first line in your script. To inspect the arguments passed to the script.
@ruslan-y : I cannot reproduce it in a test case:
See https://github.com/gabyx/githooks/compare/bugfix%2Fissue-172?expand=1
@gabyx Hello!
I've added echo "Args:" "$@"
at the first line in my script and i'm getting nothing Args:
Also I tried using your script above and see the following error
π¦ Launching '[1]' global shared hooks [type: 'pre-commit', threads: '8']...
β Hook '/Users/user/.githooks/shared/5ec0d3fe1b8fde8f8b7e34017c39a2a64aab6456-git-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg' failed!
-> errors:
β Command failed: '/Users/user/.githooks/shared/5ec0d3fe1b8fde8f8b7e34017c39a2a64aab6456-git-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg []'.
β exit status 1
β Some hooks failed, check output for details:
β’ 'ns:5ec0d3fe1b/pre-commit/prepare-commit-msg'
β Fatal error -> Abort.
what was the git command you executed. I assume you do not run this share hook containerized
?
We need probably a debug build with debug log:
I assume you are on macOS:
git hooks --version
Should be 3.0.2:
Would help if you would checkout this repo on main and build it (just needs go, there is a nix/flake.nix if you use Nix...)
./githooks/scripts/build.sh
and then change the runner temporarily in your repository where you have the hooks:
git config --local githooks.runner "<githooks-checkout>/githooks/bin/githooks-runner"
and then run inside the repo:
git commit --allow-empty -m "Test"
There should be a ton of output now.
I use git command git commit -m "my commit"
Yes, I'm on macOS, but I tried it on Ubuntu. The same issue
I ran build.sh
script and changed the runner path in local repository, then I make a commit using your test script
π Githooks Runner [version: 3.0.2+4.a89d530]
π Install dir set to: '/root/.githooks'.
π Settings:
β’ Args: '[]'
β’ Repo Path: '/root/tt'
β’ Repo Hooks: '/root/tt/.githooks'
β’ Git Dir Worktree: '/root/tt/.git'
β’ Install Dir: '/root/.githooks'
β’ Hook Path: '/root/.githooks/templates/hooks/pre-commit'
β’ Hook Name: 'pre-commit'
β’ Trusted: 'false'
β’ Containerized: 'false'
π Repository already registered.
π Checksum store contains '0' checksums
and directory search path '/root/tt/.git/.githooks.checksums'.
π User ignore patterns: '{[] []}'.
π Accumuldated repository ignore patterns: '{[] []}'.
π Exporting staged files:
- 1234
- tt
π Old hook 'pre-commit.replaced.githook' does not exist. -> Skip!
π Namespace envs: map[]
π Getting hooks in '/root/tt/.githooks'
π Shared hooks not updated.
π Getting hooks in '/root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks'
π Local Hooks: none
π Repo Shared Hooks: none
π Local Shared Hooks: none
π Global Shared Hooks :
Batch: 0
- '/root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg' []
π Hooks priority list written to '/tmp/2812734871-githooks-prio-list-pre-commit.json'.
π¦ Launching '[1]' global shared hooks [type: 'pre-commit', threads: '24']...
/root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg: line 11: /root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks/general.sh: No such file or directory
β Hook '/root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg' failed!
-> errors:
β Command failed: '/root/.githooks/shared/c172ade2e6c1d22e00277c22fdeb49910ddea6ea-https-gitlab-com-project-githooks-git/githooks/pre-commit/prepare-commit-msg []'.
β exit status 1
β Some hooks failed, check output for details:
β’ 'ns:c172ade2e6/pre-commit/prepare-commit-msg'
β Fatal error -> Abort.
Ah nice, thanks that helps. I see now that, somehow there is no Args: []
at the beginning. These are the arguments witch which the runner was called. LOL: the error you have is that you run prepare-commit-msg
under a hook pre-commit
so this is not right. You need to make a folder prepare-commit-msg/check-it.sh
then it works (or only the file prepare-commit-msg.sh
. Sorry that was a long round trip. Sometimes its better to share complete MWE to quickly help.
Reopen if it still does not work!
Hi there!
I used git hook in local repo for few project. The bash script located in folder
.git/hooks/prepare-commit-msg
and works fine.After I switched to shared githooks, I can no longer use it as before. I am getting some errors related to bash arguments that are not being passed properly.
Maybe you've come across something similar? Any answers are appreciated.