mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
Improve and fix the error message when a file is not tracked by Git
(cherry picked from commit 62e2304891
)
This commit is contained in:
parent
b9ad90d447
commit
8703e9d89e
1 changed files with 15 additions and 5 deletions
|
@ -534,11 +534,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);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue