From d7da6c9ea9459a2fa17c3e409120c5cdfde6afdc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 21 Nov 2017 19:12:47 +0100 Subject: [PATCH] fetchGit/fetchMercurial: Fix directory inclusion check E.g. the existence of .gitignore would cause .git to be included. --- src/libexpr/primops/fetchGit.cc | 5 +++-- src/libexpr/primops/fetchMercurial.cc | 5 +++-- tests/fetchGit.sh | 4 +++- tests/fetchMercurial.sh | 4 +++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc index bca68ed72..fd3e84c29 100644 --- a/src/libexpr/primops/fetchGit.cc +++ b/src/libexpr/primops/fetchGit.cc @@ -56,8 +56,9 @@ GitInfo exportGit(ref store, const std::string & uri, auto st = lstat(p); if (S_ISDIR(st.st_mode)) { - auto i = files.lower_bound(file); - return i != files.end() && hasPrefix(*i, file); + auto prefix = file + "/"; + auto i = files.lower_bound(prefix); + return i != files.end() && hasPrefix(*i, prefix); } return files.count(file); diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index 7def7103b..a317476c5 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -52,8 +52,9 @@ HgInfo exportMercurial(ref store, const std::string & uri, auto st = lstat(p); if (S_ISDIR(st.st_mode)) { - auto i = files.lower_bound(file); - return i != files.end() && hasPrefix(*i, file); + auto prefix = file + "/"; + auto i = files.lower_bound(prefix); + return i != files.end() && hasPrefix(*i, prefix); } return files.count(file); diff --git a/tests/fetchGit.sh b/tests/fetchGit.sh index f13de89f7..7b13b587d 100644 --- a/tests/fetchGit.sh +++ b/tests/fetchGit.sh @@ -16,7 +16,8 @@ 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 +touch $repo/.gitignore +git -C $repo add hello .gitignore git -C $repo commit -m 'Bla1' rev1=$(git -C $repo rev-parse HEAD) @@ -68,6 +69,7 @@ path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath") [ ! -e $path2/hello ] [ ! -e $path2/bar ] [ ! -e $path2/dir2/bar ] +[ ! -e $path2/.git ] [[ $(cat $path2/dir1/foo) = foo ]] [[ $(nix eval --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]] diff --git a/tests/fetchMercurial.sh b/tests/fetchMercurial.sh index 6cfc0a708..271350ecd 100644 --- a/tests/fetchMercurial.sh +++ b/tests/fetchMercurial.sh @@ -16,7 +16,8 @@ echo '[ui]' >> $repo/.hg/hgrc echo 'username = Foobar ' >> $repo/.hg/hgrc echo utrecht > $repo/hello -hg add --cwd $repo hello +touch $repo/.hgignore +hg add --cwd $repo hello .hgignore hg commit --cwd $repo -m 'Bla1' rev1=$(hg log --cwd $repo -r tip --template '{node}') @@ -69,6 +70,7 @@ path2=$(nix eval --raw "(builtins.fetchMercurial $repo).outPath") [ ! -e $path2/hello ] [ ! -e $path2/bar ] [ ! -e $path2/dir2/bar ] +[ ! -e $path2/.hg ] [[ $(cat $path2/dir1/foo) = foo ]] [[ $(nix eval --raw "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]]