8000 Local git rev fetch uses checked out .gitattributes · Issue #16556 · NixOS/nix · GitHub
[go: up one dir, main page]

Skip to content

Local git rev fetch uses checked out .gitattributes #16556

Open

Description

@yorickvP

Describe the bug

When builtins.fetchGit fetches a specific rev from a local repository, export-ignore attributes are read from the repo's checked out .gitattributes, not only from the commit. An untracked or staged .gitattributes changes which files a locked fetch returns.

This also causes an invalid entry into the fetcher cache.

Steps To Reproduce

#!/usr/bin/env bash
set -eu
NIX=${NIX:-nix}
repo=$(mktemp -d); cd "$repo"
git init -q
echo a > a; echo b > b
git add a b
git -c user.name=x -c user.email=x@x commit -qm init
REV=$(git rev-parse HEAD)

f() {
  XDG_CACHE_HOME=$(mktemp -d) $NIX eval --impure --raw --expr "
    let src = builtins.fetchGit { url = \"file://$repo\"; rev = \"$REV\"; };
    in builtins.toString (builtins.attrNames (builtins.readDir src)) + \"  \" + src.narHash"
  echo
}

echo "# clean:";                          f
echo 'b export-ignore' > .gitattributes
echo "# untracked .gitattributes:";       f
git add .gitattributes
echo "# staged .gitattributes:";          f
git rm -q --cached .gitattributes
echo "# git archive $REV (for comparison):"
git archive "$REV" | tar t | tr '\n' ' '; echo

Output on master (f83a7f3):

# clean:
a b  sha256-0Xf/1XMrqQr2h28ZDl0MkrZAw0dWcJZsR7Zz1VXHmqk=
# untracked .gitattributes:
a  sha256-ZC9jnmoT/hJWt2mz/0FE9wqQ0718VSOdPlkpQKJXNLg=
# staged .gitattributes:
a  sha256-ZC9jnmoT/hJWt2mz/0FE9wqQ0718VSOdPlkpQKJXNLg=
# git archive <rev> (for comparison):
a b

Without the per-call XDG_CACHE_HOME, the second and third calls still print the first narHash (sha256-0Xf/…) while readDir shows only a. The cached hash then disagrees with the actual contents.

Expected behavior

For a fetch pinned to a rev, only .gitattributes from that commit should be considered (and .git/info/attributes to match git archive). Uncommitted working-tree or index files shouldn't count. The result should not differ from a remote fetch.

Metadata

nix (Nix) 2.36.0pre20261001_f83a7f3

Additional context

Found by claude-opus-5.5.

Checklist


Add 👍 to issues you find important.

Activity

  1. added
    fetchingNetworking with the outside (non-Nix) world, input locking
    on Oct 3, 2026
  2. xokdvium commented on Oct 3, 2026

    @xokdvium
    Contributor

    (and .git/info/attributes to match git archive).

    It probably shouldn't for the exact same reason as accessing from the local checkout is bad. We also shouldn't read from the global config and I think we do try to avoid being affected by it? At least it should be the case.

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

    bugfetchingNetworking with the outside (non-Nix) world, input locking

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0