2017-11-01 15:32:53 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
if [[ -z $(type -p hg) ]]; then
|
|
|
|
echo "Mercurial not installed; skipping Mercurial tests"
|
2017-11-07 11:06:58 +00:00
|
|
|
exit 99
|
2017-11-01 15:32:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
repo=$TEST_ROOT/hg
|
|
|
|
|
2020-03-17 19:54:36 +00:00
|
|
|
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix
|
2017-11-01 15:32:53 +00:00
|
|
|
|
|
|
|
hg init $repo
|
|
|
|
echo '[ui]' >> $repo/.hg/hgrc
|
|
|
|
echo 'username = Foobar <foobar@example.org>' >> $repo/.hg/hgrc
|
|
|
|
|
2020-11-23 16:12:33 +00:00
|
|
|
# Set ui.tweakdefaults to ensure HGPLAIN is being set.
|
|
|
|
echo 'tweakdefaults = True' >> $repo/.hg/hgrc
|
|
|
|
|
2017-11-01 15:32:53 +00:00
|
|
|
echo utrecht > $repo/hello
|
2017-11-21 18:12:47 +00:00
|
|
|
touch $repo/.hgignore
|
|
|
|
hg add --cwd $repo hello .hgignore
|
2017-11-01 15:32:53 +00:00
|
|
|
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}')
|
|
|
|
|
2017-11-01 17:43:11 +00:00
|
|
|
# Fetch the default branch.
|
2019-11-26 23:05:30 +00:00
|
|
|
path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[[ $(cat $path/hello) = world ]]
|
|
|
|
|
2018-01-16 17:50:38 +00:00
|
|
|
# In pure eval mode, fetchGit without a revision should fail.
|
2019-11-26 23:05:30 +00:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.readFile (fetchMercurial file://$repo + \"/hello\"))") = world ]]
|
|
|
|
(! nix eval --raw --expr "builtins.readFile (fetchMercurial file://$repo + \"/hello\")")
|
2018-01-16 17:50:38 +00:00
|
|
|
|
2017-11-01 17:43:11 +00:00
|
|
|
# Fetch using an explicit revision hash.
|
2019-11-26 23:05:30 +00:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
2017-11-01 17:43:11 +00:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2018-01-16 17:50:38 +00:00
|
|
|
# In pure eval mode, fetchGit with a revision should succeed.
|
2019-11-26 23:05:30 +00:00
|
|
|
[[ $(nix eval --raw --expr "builtins.readFile (fetchMercurial { url = file://$repo; rev = \"$rev2\"; } + \"/hello\")") = world ]]
|
2018-01-16 17:50:38 +00:00
|
|
|
|
2017-11-01 15:32:53 +00:00
|
|
|
# Fetch again. This should be cached.
|
|
|
|
mv $repo ${repo}-tmp
|
2019-11-26 23:05:30 +00:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2019-11-26 23:05:30 +00:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).branch") = default ]]
|
|
|
|
[[ $(nix eval --impure --expr "(builtins.fetchMercurial file://$repo).revCount") = 1 ]]
|
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).rev") = $rev2 ]]
|
2017-11-01 15:32:53 +00:00
|
|
|
|
|
|
|
# But with TTL 0, it should fail.
|
2020-03-17 19:54:36 +00:00
|
|
|
(! nix eval --impure --refresh --expr "builtins.fetchMercurial file://$repo")
|
2017-11-01 15:32:53 +00:00
|
|
|
|
2017-11-01 17:43:11 +00:00
|
|
|
# Fetching with a explicit hash should succeed.
|
2020-03-17 19:54:36 +00:00
|
|
|
path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
2017-11-01 17:43:11 +00:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2020-03-17 19:54:36 +00:00
|
|
|
path2=$(nix eval --refresh --raw --expr "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev1\"; }).outPath")
|
2017-11-01 17:43:11 +00:00
|
|
|
[[ $(cat $path2/hello) = utrecht ]]
|
|
|
|
|
2017-11-01 15:32:53 +00:00
|
|
|
mv ${repo}-tmp $repo
|
|
|
|
|
|
|
|
# Using a clean working tree should produce the same result.
|
2019-11-26 23:05:30 +00:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
|
|
|
# Using an unclean tree should yield the tracked but uncommitted changes.
|
2017-11-03 12:48:02 +00:00
|
|
|
mkdir $repo/dir1 $repo/dir2
|
|
|
|
echo foo > $repo/dir1/foo
|
2017-11-01 15:32:53 +00:00
|
|
|
echo bar > $repo/bar
|
2017-11-03 12:48:02 +00:00
|
|
|
echo bar > $repo/dir2/bar
|
|
|
|
hg add --cwd $repo dir1/foo
|
2017-11-01 15:32:53 +00:00
|
|
|
hg rm --cwd $repo hello
|
|
|
|
|
2019-11-26 23:05:30 +00:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[ ! -e $path2/hello ]
|
|
|
|
[ ! -e $path2/bar ]
|
2017-11-03 12:48:02 +00:00
|
|
|
[ ! -e $path2/dir2/bar ]
|
2017-11-21 18:12:47 +00:00
|
|
|
[ ! -e $path2/.hg ]
|
2017-11-03 12:48:02 +00:00
|
|
|
[[ $(cat $path2/dir1/foo) = foo ]]
|
2017-11-01 15:32:53 +00:00
|
|
|
|
2019-11-26 23:05:30 +00:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]]
|
2017-11-01 15:32:53 +00:00
|
|
|
|
2020-01-21 22:49:32 +00:00
|
|
|
# ... unless we're using an explicit ref.
|
|
|
|
path3=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = $repo; rev = \"default\"; }).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[[ $path = $path3 ]]
|
|
|
|
|
|
|
|
# Committing should not affect the store path.
|
|
|
|
hg commit --cwd $repo -m 'Bla3'
|
|
|
|
|
2020-03-17 19:54:36 +00:00
|
|
|
path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
|
2017-11-01 15:32:53 +00:00
|
|
|
[[ $path2 = $path4 ]]
|