Skip to content

.exe hook in a relative hooks folder fails: "cannot spawn .git/hooks/pre-commit.exe: No such file or directory" #6542

Open

Description

@YevheniiKotyrlo

Existing issues matching what you're seeing

  • I was not able to find an open or closed issue matching what I'm seeing

Git for Windows version

git version 2.56.0.windows.4
cpu: x86_64
built from commit: 581291682ad5a238c08c93d1f5bd4518382a3230
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
rust: disabled
feature: fsmonitor--daemon
gettext: enabled
libcurl: 8.23.0
OpenSSL: OpenSSL 3.5.9 29 Sep 2026
zlib: 1.3.2
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1

Windows version

Windows 11

Windows CPU architecture

x86_64 (64-bit)

Additional Windows version information

Microsoft Windows [Version 10.0.26300.9711]

Options set during installation

None: PortableGit-2.56.0.4-64-bit.7z.exe from the v2.56.0.windows.4 release, extracted and run from its bin\bash.exe, so there is no install-options.txt.
My installed Git for Windows 2.56.0.windows.2 (default options) fails the same way.

Other interesting things

A hook that is a script (.git/hooks/pre-commit with a shebang) runs fine. Only a hook that is an executable found through the .exe extension fails, and only while the hooks folder is reached by a relative path whose separators are forward slashes.

Terminal/shell

Git Bash

Commands that trigger the issue

# https://gist.github.com/YevheniiKotyrlo/49db74140d9ed62a99b65e594424980f
# bash exe-hook-repro.sh
git --version
work="$(mktemp -d)"
cd "$work"
: > empty.gitconfig
export GIT_CONFIG_GLOBAL="$(pwd -W)/empty.gitconfig"
git init -q repository
cd repository
git config user.email repro@example.com
git config user.name repro
cp /c/Windows/System32/whoami.exe .git/hooks/pre-commit.exe

echo "--- core.hooksPath unset"
git commit -q --allow-empty -m one
echo "exit code: $?"

git config core.hooksPath .git/hooks
echo "--- core.hooksPath=$(git config core.hooksPath)"
git commit -q --allow-empty -m two
echo "exit code: $?"

git config core.hooksPath "$(pwd -W)/.git/hooks"
echo "--- core.hooksPath=$(git config core.hooksPath)"
git commit -q --allow-empty -m three
echo "exit code: $?"

Expected behaviour

Git finds .git/hooks/pre-commit.exe as the pre-commit hook and runs it in all three commits, so each prints the user name and exits 0.

Actual behaviour

The first two commits fail before the hook starts; only the commit with core.hooksPath set to an absolute path runs it:

git version 2.56.0.windows.4
--- core.hooksPath unset
error: cannot spawn .git/hooks/pre-commit.exe: No such file or directory
exit code: 1
--- core.hooksPath=.git/hooks
error: cannot spawn .git/hooks/pre-commit.exe: No such file or directory
exit code: 1
--- core.hooksPath=C:/Users/yevhe.YEVHENII/AppData/Local/Temp/tmp.Hbl8OKVvTg/repository/.git/hooks
yevhenii\yevhenii
exit code: 0

I tried a few more shapes of core.hooksPath on the same build: ./.git/hooks and a folder hooks-copy in the worktree both fail the same way, while .git\hooks (a backslash) runs the hook.

From reading the code at 5812916: find_hook() returns the relative .git/hooks/pre-commit.exe (hook.c#L103 makes it absolute only when the hook runs in another directory). path_lookup() returns a name holding a slash as it is (compat/mingw.c#L2005), so cmd equals argv[0] and mingw_spawnve_fd() leaves wcmd empty (compat/mingw.c#L2295) and calls CreateProcessW() with a NULL application name (compat/mingw.c#L2370). CreateProcessW() then parses the program out of the command line, and a relative name with only forward slashes in it does not resolve to the file in the current directory, which matches the backslash case working.

Repository

None: the script makes a new repository in a temporary folder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions