diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-12-11 23:05:51 +0100 |
---|---|---|
committer | github-actions[bot] <github-actions[bot]@users.noreply.github.com> | 2023-12-13 05:09:23 +0000 |
commit | a870ba59308d7a86ccf00f6350d7df15aed10105 (patch) | |
tree | f9ae246bb458864da6297e80e9b99858ef88b358 /lib/fileset | |
parent | bc946ac7cd7b04736dfe00437e35a1d798239b0f (diff) |
lib.fileset.gitTracked: Improve error when passing files
(cherry picked from commit 6e3be6ddb0c9789d8b891318c526a9401dab481e)
Diffstat (limited to 'lib/fileset')
-rw-r--r-- | lib/fileset/internal.nix | 2 | ||||
-rwxr-xr-x | lib/fileset/tests.sh | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index ade21fd876104..9de5590d3effd 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -874,6 +874,8 @@ rec { throw "lib.fileset.${function}: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`. See https://github.com/NixOS/nix/issues/9292." else if ! isPath path then throw "lib.fileset.${function}: Expected the ${argument} to be a path, but it's a ${typeOf path} instead." + else if pathType path != "directory" then + throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to be a directory, but it's a file instead." # We can identify local working directories by checking for .git, # see https://git-scm.com/docs/gitrepository-layout#_description. # Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`), diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index 077aefe371c35..d55c4fbfdbeb1 100755 --- a/lib/fileset/tests.sh +++ b/lib/fileset/tests.sh @@ -1317,6 +1317,12 @@ rm -rf -- * expectFailure 'gitTracked null' 'lib.fileset.gitTracked: Expected the argument to be a path, but it'\''s a null instead.' expectFailure 'gitTrackedWith {} null' 'lib.fileset.gitTrackedWith: Expected the second argument to be a path, but it'\''s a null instead.' +# The path must be a directory +touch a +expectFailure 'gitTracked ./a' 'lib.fileset.gitTracked: Expected the argument \('"$work"'/a\) to be a directory, but it'\''s a file instead' +expectFailure 'gitTrackedWith {} ./a' 'lib.fileset.gitTrackedWith: Expected the second argument \('"$work"'/a\) to be a directory, but it'\''s a file instead' +rm -rf -- * + # The path has to contain a .git directory expectFailure 'gitTracked ./.' 'lib.fileset.gitTracked: Expected the argument \('"$work"'\) to point to a local working tree of a Git repository, but it'\''s not.' expectFailure 'gitTrackedWith {} ./.' 'lib.fileset.gitTrackedWith: Expected the second argument \('"$work"'\) to point to a local working tree of a Git repository, but it'\''s not.' |