nix-super/tests/nixos/fetch-git/test-cases/shallow-cache-separation/default.nix
DavHau bc00fa4647 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
2024-01-19 20:30:47 +07:00

57 lines
1.6 KiB
Nix

{
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}"
'';
}