-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetchTree/fetchGit: re-enable shallow fetching
Add several tests for git fetching: - shallow-cache-separation: can fetch the same repo shallowly and non-shallowly - shallow-ignore-ref: ensure that ref gets ignored when shallow=true is set - ssh-shallow: can fetch a git repo via ssh using shallow=1
- Loading branch information
Showing
6 changed files
with
168 additions
and
8 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
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
57 changes: 57 additions & 0 deletions
57
tests/nixos/fetch-git/test-cases/shallow-cache-separation/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,57 @@ | ||
{ | ||
description = "can fetch the same repo shallowly and non-shallowly"; | ||
script = '' | ||
# create branch1 off of main | ||
client.succeed(f""" | ||
echo chiang-mai > {repo.path}/thailand \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit1' \ | ||
\ | ||
&& {repo.git} push origin --all | ||
""") | ||
# save the revision | ||
mainRev = client.succeed(f""" | ||
{repo.git} rev-parse main | ||
""").strip() | ||
# fetch shallowly | ||
revCountShallow = client.succeed(f""" | ||
nix eval --impure --expr ' | ||
(builtins.fetchGit {{ | ||
url = "{repo.remote}"; | ||
rev = "{mainRev}"; | ||
shallow = true; | ||
}}).revCount | ||
' | ||
""").strip() | ||
# ensure the revCount is 0 | ||
assert revCountShallow == "0", f"revCountShallow should be 0, but is {revCountShallow}" | ||
# fetch non-shallowly | ||
revCountNonShallow = client.succeed(f""" | ||
nix eval --impure --expr ' | ||
(builtins.fetchGit {{ | ||
url = "{repo.remote}"; | ||
rev = "{mainRev}"; | ||
shallow = false; | ||
}}).revCount | ||
' | ||
""").strip() | ||
# ensure the revCount is 1 | ||
assert revCountNonShallow == "1", f"revCountNonShallow should be 1, but is {revCountNonShallow}" | ||
# fetch shallowly again | ||
revCountShallow2 = client.succeed(f""" | ||
nix eval --impure --expr ' | ||
(builtins.fetchGit {{ | ||
url = "{repo.remote}"; | ||
rev = "{mainRev}"; | ||
shallow = true; | ||
}}).revCount | ||
' | ||
""").strip() | ||
# ensure the revCount is 0 | ||
assert revCountShallow2 == "0", f"revCountShallow2 should be 0, but is {revCountShallow2}" | ||
''; | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/nixos/fetch-git/test-cases/shallow-ignore-ref/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,40 @@ | ||
{ | ||
description = "ensure that ref gets ignored when shallow=true is set"; | ||
script = '' | ||
# create branch1 off of main | ||
client.succeed(f""" | ||
echo chiang-mai > {repo.path}/thailand \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit1' \ | ||
\ | ||
&& {repo.git} checkout -b branch1 main \ | ||
&& echo bangkok > {repo.path}/thailand \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit2' \ | ||
\ | ||
&& {repo.git} push origin --all | ||
""") | ||
# save the revisions | ||
mainRev = client.succeed(f""" | ||
{repo.git} rev-parse main | ||
""").strip() | ||
branch1Rev = client.succeed(f""" | ||
{repo.git} rev-parse branch1 | ||
""").strip() | ||
# Ensure that ref gets ignored when fetching shallowly. | ||
# This would fail if the ref was respected, as branch1Rev is not on main. | ||
client.succeed(f""" | ||
nix eval --impure --raw --expr ' | ||
(builtins.fetchGit {{ | ||
url = "{repo.remote}"; | ||
rev = "{branch1Rev}"; | ||
ref = "main"; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
description = "can fetch a git repo via ssh using shallow=1"; | ||
script = '' | ||
# add a file to the repo | ||
client.succeed(f""" | ||
echo chiang-mai > {repo.path}/thailand \ | ||
&& {repo.git} add thailand \ | ||
&& {repo.git} commit -m 'commit1' | ||
""") | ||
# memoize the revision | ||
rev1 = client.succeed(f""" | ||
{repo.git} rev-parse HEAD | ||
""").strip() | ||
# push to the server | ||
client.succeed(f""" | ||
{repo.git} push origin-ssh main | ||
""") | ||
fetchGit_expr = f""" | ||
builtins.fetchGit {{ | ||
url = "{repo.remote_ssh}"; | ||
rev = "{rev1}"; | ||
shallow = true; | ||
}} | ||
""" | ||
# fetch the repo via nix | ||
fetched1 = client.succeed(f""" | ||
nix eval --impure --raw --expr '({fetchGit_expr}).outPath' | ||
""") | ||
# check if the committed file is there | ||
client.succeed(f""" | ||
test -f {fetched1}/thailand | ||
""") | ||
# check if the revision is the same | ||
rev1_fetched = client.succeed(f""" | ||
nix eval --impure --raw --expr '({fetchGit_expr}).rev' | ||
""").strip() | ||
assert rev1 == rev1_fetched, f"rev1: {rev1} != rev1_fetched: {rev1_fetched}" | ||
# check if revCount is 1 | ||
revCount1 = client.succeed(f""" | ||
nix eval --impure --expr '({fetchGit_expr}).revCount' | ||
""").strip() | ||
print(f"revCount1: {revCount1}") | ||
assert revCount1 == '0', f"rev count is not 0 but {revCount1}" | ||
''; | ||
} |
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 |
---|---|---|
|
@@ -72,4 +72,4 @@ in | |
""") | ||
''; | ||
}; | ||
} | ||
} |