1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Improve and fix the error message when a file is not tracked by Git

This commit is contained in:
Graham Christensen 2025-03-31 21:35:15 -04:00 committed by Eelco Dolstra
parent cf409fd250
commit 62e2304891

View file

@ -532,11 +532,21 @@ struct GitInputScheme : InputScheme
static MakeNotAllowedError makeNotAllowedError(std::string url)
{
return [url{std::move(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 [url{std::move(url)}](const CanonPath & path) -> RestrictedPathError {
if (nix::pathExists(url + "/" + path.abs())) {
auto relativePath = path.rel(); // .makeRelative(CanonPath("/"));
return RestrictedPathError(
"'%s' is not tracked by Git.\n"
"\n"
"To use '%s', stage it in the Git repository at '%s':\n"
"\n"
"git add %s",
relativePath,
relativePath,
url,
relativePath);
} else
return RestrictedPathError("path '%s' does not exist in Git repository '%s'", path, url);
};
}