Hello,
I found a reproducible bug in `git commit -a`.
With an unresolved merge conflict present, if a different tracked file has been deleted from the working tree, `git commit -a` can crash with:
fatal: unable to stat 'bystander.txt': No such file or directory
I can reproduce this reliably with Git 2.53.0 on macOS in a fresh repository.
To reproduce:
1. Create two tracked files with identical content. 2. Create a merge conflict on one of them. 3. Delete the other tracked file from the working tree. 4. Run `git commit -a -m test`.
Expected:
Git should either stage the deletion and then stop because of the unresolved merge, or refuse the commit because of the unresolved merge, but not crash trying to stat the deleted path.
Actual:
Git aborts with:
fatal: unable to stat 'bystander.txt': No such file or directory
Reproducer script follows.
Possible cause:
This appears to involve rename detection during `add_files_to_cache()`: the deleted file gets paired with the unmerged path, and a later index update tries to `stat()` the deleted path.
Thanks,
Nick Golden nreesegolden@gmail.com
---8<--- #!/bin/sh set -eu
repro_dir="$(mktemp -d "${TMPDIR:-/tmp}/git-commit-a-rename-crash.XXXXXX")" echo "Working in: $repro_dir" cd "$repro_dir"
git init -b main git config user.name "Test User" git config user.email "test@example.com"
i=1
while [ "$i" -le 100 ]; do
printf 'line %s: shared content that is identical across both files\n' "$i"
i=$((i + 1))
done > conflict.txtcp conflict.txt bystander.txt
git add conflict.txt bystander.txt git commit -m "initial"
git checkout -b feature perl -0pi -e 's/line 50:.*$/line 50: FEATURE BRANCH CHANGE/m' conflict.txt git add conflict.txt git commit -m "feature"
git checkout main perl -0pi -e 's/line 50:.*$/line 50: MAIN BRANCH CHANGE/m' conflict.txt git add conflict.txt git commit -m "main"
git merge feature || true rm bystander.txt
set +e output="$(git commit -a -m test 2>&1)" status=$? set -e
printf '%s\n' "$output" printf 'exit status: %s\n' "$status"
case "$output" in
*"fatal: unable to stat 'bystander.txt': No such file or directory"*)
echo "Bug reproduced."
exit 0
;;
*)
echo "Did not reproduce the expected failure."
exit 1
;;
esac