Git development
 help / color / mirror / Atom feed
* BUG: git commit -a crashes with "unable to stat" during unresolved merge
@ 2026-03-31 21:53 Nick Golden
  2026-04-01 17:05 ` [PATCH] read-cache: disable renames in add_files_to_cache blindmansion
  2026-04-01 19:00 ` [PATCH v2] " Nick Golden
  0 siblings, 2 replies; 5+ messages in thread
From: Nick Golden @ 2026-03-31 21:53 UTC (permalink / raw)
  To: git

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.txt

cp 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-01 19:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 21:53 BUG: git commit -a crashes with "unable to stat" during unresolved merge Nick Golden
2026-04-01 17:05 ` [PATCH] read-cache: disable renames in add_files_to_cache blindmansion
2026-04-01 18:16   ` Junio C Hamano
2026-04-01 19:00 ` [PATCH v2] " Nick Golden
2026-04-01 19:08   ` Blind Mansion

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox