2017-11-03 14:33:50 +02:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
if [[ -z $(type -p git) ]]; then
|
|
|
|
echo "Git not installed; skipping Git tests"
|
2017-11-07 13:06:58 +02:00
|
|
|
exit 99
|
2017-11-03 14:33:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
repo=$TEST_ROOT/git
|
|
|
|
|
2019-04-19 15:06:27 +03:00
|
|
|
export _NIX_FORCE_HTTP=1
|
|
|
|
|
2018-08-17 17:29:32 +03:00
|
|
|
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix/gitv2
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
git init $repo
|
|
|
|
git -C $repo config user.email "foobar@example.com"
|
|
|
|
git -C $repo config user.name "Foobar"
|
|
|
|
|
|
|
|
echo utrecht > $repo/hello
|
2017-11-21 20:12:47 +02:00
|
|
|
touch $repo/.gitignore
|
|
|
|
git -C $repo add hello .gitignore
|
2017-11-03 14:33:50 +02:00
|
|
|
git -C $repo commit -m 'Bla1'
|
|
|
|
rev1=$(git -C $repo rev-parse HEAD)
|
|
|
|
|
|
|
|
echo world > $repo/hello
|
|
|
|
git -C $repo commit -m 'Bla2' -a
|
|
|
|
rev2=$(git -C $repo rev-parse HEAD)
|
|
|
|
|
|
|
|
# Fetch the default branch.
|
2019-04-09 00:19:19 +03:00
|
|
|
path=$(nix eval --impure --raw "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $(cat $path/hello) = world ]]
|
|
|
|
|
2018-01-16 19:50:38 +02:00
|
|
|
# In pure eval mode, fetchGit without a revision should fail.
|
2019-04-09 00:19:19 +03:00
|
|
|
[[ $(nix eval --impure --raw "(builtins.readFile (fetchGit file://$repo + \"/hello\"))") = world ]]
|
2019-04-08 17:11:36 +03:00
|
|
|
(! nix eval --raw "(builtins.readFile (fetchGit file://$repo + \"/hello\"))")
|
2018-01-16 19:50:38 +02:00
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# Fetch using an explicit revision hash.
|
|
|
|
path2=$(nix eval --raw "(builtins.fetchGit { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2018-01-16 19:50:38 +02:00
|
|
|
# In pure eval mode, fetchGit with a revision should succeed.
|
2019-04-08 17:11:36 +03:00
|
|
|
[[ $(nix eval --raw "(builtins.readFile (fetchGit { url = file://$repo; rev = \"$rev2\"; } + \"/hello\"))") = world ]]
|
2018-01-16 19:50:38 +02:00
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# Fetch again. This should be cached.
|
|
|
|
mv $repo ${repo}-tmp
|
2019-04-09 00:19:19 +03:00
|
|
|
path2=$(nix eval --impure --raw "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2019-04-09 00:19:19 +03:00
|
|
|
[[ $(nix eval --impure "(builtins.fetchGit file://$repo).revCount") = 2 ]]
|
|
|
|
[[ $(nix eval --impure --raw "(builtins.fetchGit file://$repo).rev") = $rev2 ]]
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
# But with TTL 0, it should fail.
|
2019-04-09 00:19:19 +03:00
|
|
|
(! nix eval --impure --tarball-ttl 0 "(builtins.fetchGit file://$repo)" -vvvvv)
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
# Fetching with a explicit hash should succeed.
|
|
|
|
path2=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchGit { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
|
|
|
path2=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchGit { url = file://$repo; rev = \"$rev1\"; }).outPath")
|
|
|
|
[[ $(cat $path2/hello) = utrecht ]]
|
|
|
|
|
|
|
|
mv ${repo}-tmp $repo
|
|
|
|
|
|
|
|
# Using a clean working tree should produce the same result.
|
2019-04-09 00:19:19 +03:00
|
|
|
path2=$(nix eval --impure --raw "(builtins.fetchGit $repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
|
|
|
# Using an unclean tree should yield the tracked but uncommitted changes.
|
2017-11-03 14:48:02 +02:00
|
|
|
mkdir $repo/dir1 $repo/dir2
|
|
|
|
echo foo > $repo/dir1/foo
|
2017-11-03 14:33:50 +02:00
|
|
|
echo bar > $repo/bar
|
2017-11-03 14:48:02 +02:00
|
|
|
echo bar > $repo/dir2/bar
|
|
|
|
git -C $repo add dir1/foo
|
2017-11-03 14:33:50 +02:00
|
|
|
git -C $repo rm hello
|
|
|
|
|
2019-04-09 00:19:19 +03:00
|
|
|
path2=$(nix eval --impure --raw "(builtins.fetchGit $repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[ ! -e $path2/hello ]
|
|
|
|
[ ! -e $path2/bar ]
|
2017-11-03 14:48:02 +02:00
|
|
|
[ ! -e $path2/dir2/bar ]
|
2017-11-21 20:12:47 +02:00
|
|
|
[ ! -e $path2/.git ]
|
2017-11-03 14:48:02 +02:00
|
|
|
[[ $(cat $path2/dir1/foo) = foo ]]
|
2017-11-03 14:33:50 +02:00
|
|
|
|
2019-04-09 00:19:19 +03:00
|
|
|
[[ $(nix eval --impure --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
# ... unless we're using an explicit ref or rev.
|
2019-04-09 00:19:19 +03:00
|
|
|
path3=$(nix eval --impure --raw "(builtins.fetchGit { url = $repo; ref = \"master\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path3 ]]
|
|
|
|
|
|
|
|
path3=$(nix eval --raw "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; }).outPath")
|
|
|
|
[[ $path = $path3 ]]
|
|
|
|
|
|
|
|
# Committing should not affect the store path.
|
|
|
|
git -C $repo commit -m 'Bla3' -a
|
|
|
|
|
2019-04-09 00:19:19 +03:00
|
|
|
path4=$(nix eval --impure --tarball-ttl 0 --raw "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path2 = $path4 ]]
|
2017-11-24 04:50:01 +02:00
|
|
|
|
|
|
|
# tarball-ttl should be ignored if we specify a rev
|
|
|
|
echo delft > $repo/hello
|
|
|
|
git -C $repo add hello
|
|
|
|
git -C $repo commit -m 'Bla4'
|
|
|
|
rev3=$(git -C $repo rev-parse HEAD)
|
|
|
|
nix eval --tarball-ttl 3600 "(builtins.fetchGit { url = $repo; rev = \"$rev3\"; })" >/dev/null
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Update 'path' to reflect latest master
|
2019-04-09 00:19:19 +03:00
|
|
|
path=$(nix eval --impure --raw "(builtins.fetchGit file://$repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Check behavior when non-master branch is used
|
|
|
|
git -C $repo checkout $rev2 -b dev
|
|
|
|
echo dev > $repo/hello
|
|
|
|
|
|
|
|
# File URI uses 'master' unless specified otherwise
|
2019-04-09 00:19:19 +03:00
|
|
|
path2=$(nix eval --impure --raw "(builtins.fetchGit file://$repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
|
|
|
# Using local path with branch other than 'master' should work when clean or dirty
|
2019-04-09 00:19:19 +03:00
|
|
|
path3=$(nix eval --impure --raw "(builtins.fetchGit $repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
# (check dirty-tree handling was used)
|
2019-04-09 00:19:19 +03:00
|
|
|
[[ $(nix eval --impure --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Committing shouldn't change store path, or switch to using 'master'
|
|
|
|
git -C $repo commit -m 'Bla5' -a
|
2019-04-09 00:19:19 +03:00
|
|
|
path4=$(nix eval --impure --raw "(builtins.fetchGit $repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
[[ $(cat $path4/hello) = dev ]]
|
|
|
|
[[ $path3 = $path4 ]]
|
|
|
|
|
|
|
|
# Confirm same as 'dev' branch
|
2019-04-09 00:19:19 +03:00
|
|
|
path5=$(nix eval --impure --raw "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
[[ $path3 = $path5 ]]
|
2018-01-09 16:58:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Nuke the cache
|
2018-08-17 17:29:32 +03:00
|
|
|
rm -rf $TEST_HOME/.cache/nix/gitv2
|
2018-01-09 16:58:19 +02:00
|
|
|
|
|
|
|
# Try again, but without 'git' on PATH
|
|
|
|
NIX=$(command -v nix)
|
|
|
|
# This should fail
|
2019-04-09 00:19:19 +03:00
|
|
|
(! PATH= $NIX eval --impure --raw "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outPath" )
|
2018-01-09 16:58:19 +02:00
|
|
|
|
|
|
|
# Try again, with 'git' available. This should work.
|
2019-04-09 00:19:19 +03:00
|
|
|
path5=$(nix eval --impure --raw "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outPath")
|
2018-01-09 16:58:19 +02:00
|
|
|
[[ $path3 = $path5 ]]
|