Skip to content

Commit

Permalink
run 'git status' when another git command fails with 'fatal: not in a…
Browse files Browse the repository at this point in the history
… git directory'

'git status' prints a more informative error message than other git
commands in certain failure scenarios, specifically including when the
workspace is not owned by the user executing 'git'. Hopefully printing
this extra error message will make it more obvious to operators what is
going on if they encounter this kind of failure.
  • Loading branch information
bpholt committed Feb 9, 2024
1 parent 97598b6 commit e386d69
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit
): F[List[String]] = {
val extraEnv = List("GIT_ASKPASS" -> config.gitAskPass.pathAsString)
processAlg.exec(gitCmd ++ args.toList, repo, extraEnv, slurpOptions)
.recoverWith {
case ex: ProcessFailedException if ex.getMessage.contains("fatal: not in a git directory") =>
// `git status` prints a more informative error message than some other git commands, like `git config`
// this will hopefully print that error message to the logs in addition to the actual failure
processAlg.exec(Nel.of("git", "status"), repo, List.empty, slurpOptions).attempt.void >> ex.raiseError
}
}

private def git_(args: String*)(repo: File): F[List[String]] =
Expand Down

0 comments on commit e386d69

Please sign in to comment.