Skip to content

Commit

Permalink
add tests for fetchGit regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavHau committed Dec 29, 2023
1 parent 84af38d commit c324fec
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/nixos/fetch-git/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,75 @@
assert rev1 == rev1_fetched
'';
}
{
name = "respect-ref";
description = "ensure fetched 'rev' is reachable from specified 'ref'";
script = ''
# make an initial commit
client.succeed(f"""
echo "init" > {repo.path}/init \
&& {repo.git} add init \
&& {repo.git} commit -m 'init'
""")
# push commit1 to branch1
client.succeed(f"""
echo chiang-mai > {repo.path}/thailand \
&& {repo.git} checkout -b branch1 \
&& {repo.git} add thailand \
&& {repo.git} commit -m 'commit1' \
&& {repo.git} push origin branch1
""")
# store rev of commit1
commit1 = client.succeed(f"""
{repo.git} rev-parse HEAD
""").strip()
# push commit2 to branch2
client.succeed(f"""
{repo.git} checkout main \
&& {repo.git} checkout -b branch2 \
&& echo bangkok > {repo.path}/thailand \
&& {repo.git} add thailand \
&& {repo.git} commit -m 'commit2' \
&& {repo.git} push origin branch2
""")
# try to fetch commit1 while specifying ref=branch2
# this should fail
client.fail(f"""
nix eval --impure --raw --expr \'(builtins.fetchGit {{
url = "{repo.remote}";
rev = "{commit1}";
ref = "branch2";
}}).outPath'
""")
'';
}
{
name = "respect-gitattributes";
description = "ensure .gitattributes is respected";
script = ''
# add not-exported-file file to the repo
client.succeed(f"""
echo "not-exported-file" > {repo.path}/not-exported-file \
&& echo "not-exported-file export-ignore" >> {repo.path}/.gitattributes \
&& {repo.git} add not-exported-file .gitattributes \
&& {repo.git} commit -m 'commit1' \
&& {repo.git} push origin main
""")
# fetch the repo via nix
fetched1 = client.succeed(f"""
nix eval --impure --raw --expr "(builtins.fetchGit {repo.remote}).outPath"
""")
# ensure the file is not there
client.fail(f"""
test -f {fetched1}/not-exported-file
""")
'';
}
];
}

0 comments on commit c324fec

Please sign in to comment.