1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

shellcheck fix: tests/functional/fetchMercurial.sh

This commit is contained in:
Farid Zakaria 2025-09-25 13:13:38 -07:00
parent c4c3524318
commit 4cec876319
2 changed files with 43 additions and 43 deletions

View file

@ -106,7 +106,6 @@
enable = true; enable = true;
excludes = [ excludes = [
# We haven't linted these files yet # We haven't linted these files yet
''^tests/functional/fetchMercurial\.sh$''
''^tests/functional/fixed\.builder1\.sh$'' ''^tests/functional/fixed\.builder1\.sh$''
''^tests/functional/fixed\.builder2\.sh$'' ''^tests/functional/fixed\.builder2\.sh$''
''^tests/functional/fixed\.sh$'' ''^tests/functional/fixed\.sh$''

View file

@ -12,34 +12,35 @@ clearStore
# See https://github.com/NixOS/nix/issues/6195 # See https://github.com/NixOS/nix/issues/6195
repo=$TEST_ROOT/./hg repo=$TEST_ROOT/./hg
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix rm -rf "$repo" "${repo}"-tmp "$TEST_HOME"/.cache/nix
hg init $repo hg init "$repo"
echo '[ui]' >> $repo/.hg/hgrc {
echo 'username = Foobar <foobar@example.org>' >> $repo/.hg/hgrc echo '[ui]'
echo 'username = Foobar <foobar@example.org>'
# Set ui.tweakdefaults to ensure HGPLAIN is being set.
echo 'tweakdefaults = True'
} >> "$repo"/.hg/hgrc
# Set ui.tweakdefaults to ensure HGPLAIN is being set. echo utrecht > "$repo"/hello
echo 'tweakdefaults = True' >> $repo/.hg/hgrc touch "$repo"/.hgignore
hg add --cwd "$repo" hello .hgignore
hg commit --cwd "$repo" -m 'Bla1'
rev1=$(hg log --cwd "$repo" -r tip --template '{node}')
echo utrecht > $repo/hello echo world > "$repo"/hello
touch $repo/.hgignore hg commit --cwd "$repo" -m 'Bla2'
hg add --cwd $repo hello .hgignore rev2=$(hg log --cwd "$repo" -r tip --template '{node}')
hg commit --cwd $repo -m 'Bla1'
rev1=$(hg log --cwd $repo -r tip --template '{node}')
echo world > $repo/hello
hg commit --cwd $repo -m 'Bla2'
rev2=$(hg log --cwd $repo -r tip --template '{node}')
# Fetch an unclean branch. # Fetch an unclean branch.
echo unclean > $repo/hello echo unclean > "$repo"/hello
path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath") path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $(cat $path/hello) = unclean ]] [[ $(cat "$path"/hello) = unclean ]]
hg revert --cwd $repo --all hg revert --cwd "$repo" --all
# Fetch the default branch. # Fetch the default branch.
path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath") path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $(cat $path/hello) = world ]] [[ $(cat "$path"/hello) = world ]]
# In pure eval mode, fetchGit without a revision should fail. # In pure eval mode, fetchGit without a revision should fail.
[[ $(nix eval --impure --raw --expr "(builtins.readFile (fetchMercurial file://$repo + \"/hello\"))") = world ]] [[ $(nix eval --impure --raw --expr "(builtins.readFile (fetchMercurial file://$repo + \"/hello\"))") = world ]]
@ -47,64 +48,64 @@ path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).ou
# Fetch using an explicit revision hash. # Fetch using an explicit revision hash.
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath") path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath")
[[ $path = $path2 ]] [[ $path = "$path2" ]]
# In pure eval mode, fetchGit with a revision should succeed. # In pure eval mode, fetchGit with a revision should succeed.
[[ $(nix eval --raw --expr "builtins.readFile (fetchMercurial { url = file://$repo; rev = \"$rev2\"; } + \"/hello\")") = world ]] [[ $(nix eval --raw --expr "builtins.readFile (fetchMercurial { url = file://$repo; rev = \"$rev2\"; } + \"/hello\")") = world ]]
# Fetch again. This should be cached. # Fetch again. This should be cached.
mv $repo ${repo}-tmp mv "$repo" "${repo}"-tmp
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath") path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $path = $path2 ]] [[ $path = "$path2" ]]
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).branch") = default ]] [[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).branch") = default ]]
[[ $(nix eval --impure --expr "(builtins.fetchMercurial file://$repo).revCount") = 1 ]] [[ $(nix eval --impure --expr "(builtins.fetchMercurial file://$repo).revCount") = 1 ]]
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).rev") = $rev2 ]] [[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).rev") = "$rev2" ]]
# But with TTL 0, it should fail. # But with TTL 0, it should fail.
(! nix eval --impure --refresh --expr "builtins.fetchMercurial file://$repo") (! nix eval --impure --refresh --expr "builtins.fetchMercurial file://$repo")
# Fetching with a explicit hash should succeed. # Fetching with a explicit hash should succeed.
path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath") path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath")
[[ $path = $path2 ]] [[ $path = "$path2" ]]
path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev1\"; }).outPath") path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev1\"; }).outPath")
[[ $(cat $path2/hello) = utrecht ]] [[ $(cat "$path2"/hello) = utrecht ]]
mv ${repo}-tmp $repo mv "${repo}"-tmp "$repo"
# Using a clean working tree should produce the same result. # Using a clean working tree should produce the same result.
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath") path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath")
[[ $path = $path2 ]] [[ $path = "$path2" ]]
# Using an unclean tree should yield the tracked but uncommitted changes. # Using an unclean tree should yield the tracked but uncommitted changes.
mkdir $repo/dir1 $repo/dir2 mkdir "$repo"/dir1 "$repo"/dir2
echo foo > $repo/dir1/foo echo foo > "$repo"/dir1/foo
echo bar > $repo/bar echo bar > "$repo"/bar
echo bar > $repo/dir2/bar echo bar > "$repo"/dir2/bar
hg add --cwd $repo dir1/foo hg add --cwd "$repo" dir1/foo
hg rm --cwd $repo hello hg rm --cwd "$repo" hello
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath") path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath")
[ ! -e $path2/hello ] [ ! -e "$path2"/hello ]
[ ! -e $path2/bar ] [ ! -e "$path2"/bar ]
[ ! -e $path2/dir2/bar ] [ ! -e "$path2"/dir2/bar ]
[ ! -e $path2/.hg ] [ ! -e "$path2"/.hg ]
[[ $(cat $path2/dir1/foo) = foo ]] [[ $(cat "$path2"/dir1/foo) = foo ]]
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]] [[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]]
# ... unless we're using an explicit ref. # ... unless we're using an explicit ref.
path3=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = $repo; rev = \"default\"; }).outPath") path3=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = $repo; rev = \"default\"; }).outPath")
[[ $path = $path3 ]] [[ $path = "$path3" ]]
# Committing should not affect the store path. # Committing should not affect the store path.
hg commit --cwd $repo -m 'Bla3' hg commit --cwd "$repo" -m 'Bla3'
path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchMercurial file://$repo).outPath") path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $path2 = $path4 ]] [[ $path2 = "$path4" ]]
echo paris > $repo/hello echo paris > "$repo"/hello
# Passing a `name` argument should be reflected in the output path # Passing a `name` argument should be reflected in the output path
path5=$(nix eval -vvvvv --impure --refresh --raw --expr "(builtins.fetchMercurial { url = \"file://$repo\"; name = \"foo\"; } ).outPath") path5=$(nix eval -vvvvv --impure --refresh --raw --expr "(builtins.fetchMercurial { url = \"file://$repo\"; name = \"foo\"; } ).outPath")