-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into large-path-warning
- Loading branch information
Showing
9 changed files
with
103 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
synopsis: "`fetchTree` now fetches git repositories shallowly by default" | ||
prs: 10028 | ||
--- | ||
|
||
`builtins.fetchTree` now clones git repositories shallowly by default, which reduces network traffic and disk usage significantly in many cases. | ||
|
||
Previously, the default behavior was to clone the full history of a specific tag or branch (eg. `ref`) and only afterwards extract the files of one specific revision. | ||
|
||
From now on, the `ref` and `allRefs` arguments will be ignored, except if shallow cloning is disabled by setting `shallow = false`. | ||
|
||
The defaults for `builtins.fetchGit` remain unchanged. Here, shallow cloning has to be enabled manually by passing `shallow = true`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
source ./common.sh | ||
|
||
requireGit | ||
|
45 changes: 45 additions & 0 deletions
45
tests/nixos/fetch-git/test-cases/fetchTree-shallow/default.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
description = "fetchTree fetches git repos shallowly by default"; | ||
script = '' | ||
# purge nix git cache to make sure we start with a clean slate | ||
client.succeed("rm -rf ~/.cache/nix") | ||
# add two commits to the repo: | ||
# - one with a large file (2M) | ||
# - another one making the file small again | ||
client.succeed(f""" | ||
dd if=/dev/urandom of={repo.path}/thailand bs=1M count=2 \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit1' \ | ||
&& echo 'ThaigerSprint' > {repo.path}/thailand \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit2' \ | ||
&& {repo.git} push origin main | ||
""") | ||
# memoize the revision | ||
commit2_rev = client.succeed(f""" | ||
{repo.git} rev-parse HEAD | ||
""").strip() | ||
# construct the fetcher call | ||
fetchGit_expr = f""" | ||
builtins.fetchTree {{ | ||
type = "git"; | ||
url = "{repo.remote}"; | ||
rev = "{commit2_rev}"; | ||
}} | ||
""" | ||
# fetch the repo via nix | ||
fetched1 = client.succeed(f""" | ||
nix eval --impure --raw --expr '({fetchGit_expr}).outPath' | ||
""") | ||
# check that the size of ~/.cache/nix is less than 1M | ||
cache_size = client.succeed(""" | ||
du -s ~/.cache/nix | ||
""").strip().split()[0] | ||
assert int(cache_size) < 1024, f"cache size is {cache_size}K which is larger than 1M" | ||
''; | ||
} |