aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-11-03 13:33:50 +0100
committerEelco Dolstra <edolstra@gmail.com>2017-11-03 13:55:30 +0100
commit4dee01da7c7bc5d67dc916f159bfee8a873ac19b (patch)
tree335cc7473215f4833c58a28f6e000026f3c731de
parent0e77aa398240d04e4169208d14ea620b8507b732 (diff)
fetchGit: Add a test
-rw-r--r--release.nix3
-rw-r--r--shell.nix1
-rw-r--r--src/libexpr/primops/fetchMercurial.cc2
-rw-r--r--tests/fetchGit.sh83
-rw-r--r--tests/fetchMercurial.sh2
-rw-r--r--tests/local.mk1
6 files changed, 90 insertions, 2 deletions
diff --git a/release.nix b/release.nix
index f76e7cb9e..aa4d63777 100644
--- a/release.nix
+++ b/release.nix
@@ -76,6 +76,9 @@ let
[ curl
bzip2 xz brotli
openssl pkgconfig sqlite boehmgc
+
+ # Tests
+ git
mercurial
]
++ lib.optional stdenv.isLinux libseccomp
diff --git a/shell.nix b/shell.nix
index 02fbd59b1..f47952582 100644
--- a/shell.nix
+++ b/shell.nix
@@ -25,6 +25,7 @@ with import ./release-common.nix { inherit pkgs; };
perlPackages.DBDSQLite
# Tests
+ git
mercurial
]
++ lib.optional stdenv.isLinux libseccomp;
diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc
index f48d003fc..2a423f61b 100644
--- a/src/libexpr/primops/fetchMercurial.cc
+++ b/src/libexpr/primops/fetchMercurial.cc
@@ -72,7 +72,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri,
time_t now = time(0);
struct stat st;
if (stat(stampFile.c_str(), &st) != 0 ||
- st.st_mtime < now - settings.tarballTtl)
+ st.st_mtime <= now - settings.tarballTtl)
{
/* Except that if this is a commit hash that we already have,
we don't have to pull again. */
diff --git a/tests/fetchGit.sh b/tests/fetchGit.sh
new file mode 100644
index 000000000..e2bb7b68c
--- /dev/null
+++ b/tests/fetchGit.sh
@@ -0,0 +1,83 @@
+source common.sh
+
+if [[ -z $(type -p git) ]]; then
+ echo "Git not installed; skipping Git tests"
+ exit 0
+fi
+
+clearStore
+
+repo=$TEST_ROOT/git
+
+rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix/git
+
+git init $repo
+git -C $repo config user.email "foobar@example.com"
+git -C $repo config user.name "Foobar"
+
+echo utrecht > $repo/hello
+git -C $repo add hello
+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.
+path=$(nix eval --raw "(builtins.fetchGit file://$repo).outPath")
+[[ $(cat $path/hello) = world ]]
+
+# Fetch using an explicit revision hash.
+path2=$(nix eval --raw "(builtins.fetchGit { url = file://$repo; rev = \"$rev2\"; }).outPath")
+[[ $path = $path2 ]]
+
+# Fetch again. This should be cached.
+mv $repo ${repo}-tmp
+path2=$(nix eval --raw "(builtins.fetchGit file://$repo).outPath")
+[[ $path = $path2 ]]
+
+[[ $(nix eval "(builtins.fetchGit file://$repo).revCount") = 2 ]]
+[[ $(nix eval --raw "(builtins.fetchGit file://$repo).rev") = $rev2 ]]
+
+# But with TTL 0, it should fail.
+(! nix eval --tarball-ttl 0 "(builtins.fetchGit file://$repo)" -vvvvv)
+
+# 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.
+path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath")
+[[ $path = $path2 ]]
+
+# Using an unclean tree should yield the tracked but uncommitted changes.
+echo foo > $repo/foo
+echo bar > $repo/bar
+git -C $repo add foo
+git -C $repo rm hello
+
+path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath")
+[ ! -e $path2/hello ]
+[ ! -e $path2/bar ]
+[[ $(cat $path2/foo) = foo ]]
+
+[[ $(nix eval --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
+
+# ... unless we're using an explicit ref or rev.
+path3=$(nix eval --raw "(builtins.fetchGit { url = $repo; ref = \"master\"; }).outPath")
+[[ $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
+
+path4=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchGit file://$repo).outPath")
+[[ $path2 = $path4 ]]
diff --git a/tests/fetchMercurial.sh b/tests/fetchMercurial.sh
index 83bf1331a..9c897ada9 100644
--- a/tests/fetchMercurial.sh
+++ b/tests/fetchMercurial.sh
@@ -42,7 +42,7 @@ path2=$(nix eval --raw "(builtins.fetchMercurial file://$repo).outPath")
[[ $(nix eval --raw "(builtins.fetchMercurial file://$repo).rev") = $rev2 ]]
# But with TTL 0, it should fail.
-(! nix eval --tarball-ttl 0 --raw "(builtins.fetchMercurial file://$repo)")
+(! nix eval --tarball-ttl 0 "(builtins.fetchMercurial file://$repo)")
# Fetching with a explicit hash should succeed.
path2=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchMercurial { url = file://$repo; rev = \"$rev2\"; }).outPath")
diff --git a/tests/local.mk b/tests/local.mk
index fced281ee..67b378839 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -16,6 +16,7 @@ nix_tests = \
build-remote.sh \
nar-index.sh \
structured-attrs.sh \
+ fetchGit.sh \
fetchMercurial.sh
# parallel.sh