git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Nick Golden <nreesegolden@gmail.com>
To: git@vger.kernel.org
Subject: BUG: git commit -a crashes with "unable to stat" during unresolved merge
Date: Tue, 31 Mar 2026 17:53:16 -0400	[thread overview]
Message-ID: <CAF6hZH5TyFBm5H_fcVyaf1aw-mPsVbAmNvkUGCMoQYYCX1+HRQ@mail.gmail.com> (raw)

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


             reply	other threads:[~2026-03-31 21:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 21:53 Nick Golden [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAF6hZH5TyFBm5H_fcVyaf1aw-mPsVbAmNvkUGCMoQYYCX1+HRQ@mail.gmail.com \
    --to=nreesegolden@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).