From 593798b2a04dfb3c9875581076b1b61c11a9972a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 May 2022 22:56:39 +0200 Subject: [PATCH] Show a sensible error when a file exists but is not under git control Example: error: access to path '/home/eelco/Dev/patchelf/foo.nix' is forbidden because it is not under Git control; maybe you should 'git add' it to the repository '/home/eelco/Dev/patchelf'? Fixes #4507. --- src/libfetchers/git.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index cc4bc5152..711319659 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -715,7 +715,15 @@ struct GitInputScheme : InputScheme // FIXME: return updated input. - return {makeFSInputAccessor(CanonPath(repoInfo.url), listFiles(repoInfo)), input}; + auto makeNotAllowedError = [url{repoInfo.url}](const CanonPath & path) -> RestrictedPathError + { + if (nix::pathExists(path.abs())) + return RestrictedPathError("access to path '%s' is forbidden because it is not under Git control; maybe you should 'git add' it to the repository '%s'?", path, url); + else + return RestrictedPathError("path '%s' does not exist in Git reposity '%s'", path, url); + }; + + return {makeFSInputAccessor(CanonPath(repoInfo.url), listFiles(repoInfo), std::move(makeNotAllowedError)), input}; } };