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.
This commit is contained in:
Eelco Dolstra 2022-05-18 22:56:39 +02:00
parent 1970d6db12
commit 593798b2a0
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -715,7 +715,15 @@ struct GitInputScheme : InputScheme
// FIXME: return updated input. // 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};
} }
}; };