# [BUG] sparse-checkout: checkout clobbers untracked in-cone file

1 messages from 2026-09-30 to 2026-09-30. Participants: Webstrand.
Thread: https://gitlist.dev/t/66429

## Webstrand, 2026-09-30 20:20

Subject: [BUG] sparse-checkout: checkout clobbers untracked in-cone file
Message-ID: <CACm1TQd5b9tX368LrsD26Q6tm_mzdi1nwGtGd2V1jwYW+r2c1A@mail.gmail.com>

```
What did you do before the bug happened? (Steps to reproduce your issue)

    git init --initial-branch=locus repo
    cd repo
    mkdir src docs
    echo "tracked" >src/tracked.txt
    echo "tracked" >docs/tracked.txt
    git add .
    git commit --message="initial"
    git sparse-checkout set src
    git branch some-feature-branch
    git checkout some-feature-branch
    echo "incoming" >src/new.txt
    git add src/new.txt
    git commit --message="add src/new.txt"
    git checkout locus
    echo "local" >src/new.txt # conflicting untracked file
    git checkout some-feature-branch
    echo $?
    cat src/new.txt

What did you expect to happen? (Expected behavior)

The checkout operation should be aborted as a whole:

 1. No files in the working tree should be updated.
 2. HEAD should not be moved and should continue to reference locus.
 3. src/new.txt must be unmodified, preserving the untracked content
    "local".
 4. git should exit with status 1 and print the following error:

    error: The following untracked working tree files would be
overwritten by checkout:
        src/new.txt
    Please move or remove them before you switch branches.
    Aborting

Sparse checkouts should have the same behavior as non-sparse checkouts
of the same commits.

What happened instead? (Actual behavior)

The checkout operation clobbered untracked files:

 1. Files in the working tree were updated.
 2. HEAD was moved to reference some-feature-branch.
 3. src/new.txt was overwritten with the content "incoming", clobbering
    it.
 4. git exited with status 0 and printed the following warning:

    warning: The following paths were already present and thus not
updated despite sparse patterns:
        src/new.txt

    After fixing the above paths, you may want to run `git
sparse-checkout reapply`.
    Switched to branch 'some-feature-branch'

Additionally, the produced warning is incorrect and misleading.

What's different between what you expected and what actually happened?

The checkout completed instead of being aborted, src/new.txt was
clobbered instead of preserved, and the conflict was reported as a
warning instead of an error, and the warning was incorrect and
misleading. As a result, the untracked content of src/new.txt was
destroyed.

Anything else you want to add:

The behavior is present from v2.27.0, the first release to contain
681c637b4a, through the tip of master (a018953688).

The behavior was introduced by

681c637b4a unpack-trees: failure to set SKIP_WORKTREE bits always just a warning

Prior to 681c6, git refused the sparse checkout, producing the same
error as the non-sparse checkout, with the same behavior as in "Expected
behavior". src/new.txt was not clobbered. Starting with 681c6, git
completes the sparse checkout with the warning shown in "Actual
behavior", and src/new.txt is clobbered.

[System Info]
git version 2.56.0
cpu: x86_64
built from commit: a018953688f1b10bddf91bff8747068f5f4746a4
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
rust: enabled
feature: fsmonitor--daemon
gettext: enabled
libcurl: 8.22.0
OpenSSL: OpenSSL 3.5.3 16 Sep 2025
zlib: 1.3.1
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1
uname: Linux 7.2.7-1-default #1 SMP PREEMPT_DYNAMIC Tue Sep 22
08:00:24 UTC 2026 (e601a2d) x86_64
compiler info: gnuc: 16.2
libc info: glibc: 2.44
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
not run from a git repository - no hooks to show

```
