Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@ static void fetchTree(
attrs.emplace("exportIgnore", Explicit<bool>{true});
}

// fetchTree should fetch git repos with shallow = true by default
if (type == "git" && !params.isFetchGit && !attrs.contains("shallow")) {
attrs.emplace("shallow", Explicit<bool>{true});
}

if (!params.allowNameArgument)
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
state.error<EvalError>("argument 'name' isn’t supported in call to '%s'", fetcher)
Expand Down Expand Up @@ -300,6 +295,11 @@ static void fetchTree(
}
}

// fetchTree should fetch git repos with shallow = true by default,
// regardless of whether the input was passed as a URL or an attribute set.
if (input.getType() == "git" && !params.isFetchGit && !input.attrs.contains("shallow"))
input.attrs.emplace("shallow", Explicit<bool>{true});

if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
input = lookupInRegistries(state.fetchSettings, *state.store, input, fetchers::UseRegistries::Limited).first;

Expand Down Expand Up @@ -424,6 +424,7 @@ static RegisterPrimOp primop_fetchTree({
- `"mercurial"`

*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references).
Passing a URL-like reference directly is equivalent to passing the attribute set returned by [`builtins.parseFlakeRef`](@docroot@/language/builtins.md#builtins-parseFlakeRef).
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/development/experimental-features.md#xp-feature-flakes) to be enabled.

> **Example**
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/fetchGit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ path0_=$(nix eval --impure --raw --expr "(builtins.fetchTree { type = \"git\"; u
[[ $path0 = "$path0_" ]]
path0_=$(nix eval --impure --raw --expr "(builtins.fetchTree \"git+file://$TEST_ROOT/worktree\").outPath")
[[ $path0 = "$path0_" ]]

# Regression test for #12860: a URL-like reference and its parsed attribute set
# must use the same defaults.
nix eval --impure --expr "builtins.fetchTree \"git+file://$repo\" == builtins.fetchTree (builtins.parseFlakeRef \"git+file://$repo\")" | grepQuiet true

export _NIX_FORCE_HTTP=1
[[ $(tail -n 1 "$path0"/hello) = "hello" ]]

Expand Down