You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Local git rev fetch uses checked out .gitattributes #16556
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
# 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.
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.
Activity
xokdvium commentedon Oct 3, 2026
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.