Skip to content

Commit 70dcd73

Browse files
authored
Merge pull request #12870 from DeterminateSystems/improve-git-error
Git fetcher: Improve error message for untracked files
2 parents 7a6570a + f15681d commit 70dcd73

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/libfetchers/git.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,20 @@ struct GitInputScheme : InputScheme
530530
return *head;
531531
}
532532

533-
static MakeNotAllowedError makeNotAllowedError(std::string url)
533+
static MakeNotAllowedError makeNotAllowedError(std::filesystem::path repoPath)
534534
{
535-
return [url{std::move(url)}](const CanonPath & path) -> RestrictedPathError
536-
{
537-
if (nix::pathExists(path.abs()))
538-
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);
535+
return [repoPath{std::move(repoPath)}](const CanonPath & path) -> RestrictedPathError {
536+
if (nix::pathExists(repoPath / path.rel()))
537+
return RestrictedPathError(
538+
"Path '%1%' in the repository %2% is not tracked by Git.\n"
539+
"\n"
540+
"To make it visible to Nix, run:\n"
541+
"\n"
542+
"git -C %2% add \"%1%\"",
543+
path.rel(),
544+
repoPath);
539545
else
540-
return RestrictedPathError("path '%s' does not exist in Git repository '%s'", path, url);
546+
return RestrictedPathError("Path '%s' does not exist in Git repository %s.", path.rel(), repoPath);
541547
};
542548
}
543549

@@ -747,7 +753,7 @@ struct GitInputScheme : InputScheme
747753
ref<SourceAccessor> accessor =
748754
repo->getAccessor(repoInfo.workdirInfo,
749755
exportIgnore,
750-
makeNotAllowedError(repoInfo.locationToArg()));
756+
makeNotAllowedError(repoPath));
751757

752758
/* If the repo has submodules, return a mounted input accessor
753759
consisting of the accessor for the top-level repo and the

0 commit comments

Comments
 (0)