From 4f00f5965e140abb8d911b54f679c37b706d28af Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Fri, 9 Feb 2024 15:56:05 -0600 Subject: [PATCH] run 'git status' when another git command fails with 'fatal: not in a 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. --- .../org/scalasteward/core/git/FileGitAlg.scala | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala index a82182024a..49138b8001 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala @@ -151,7 +151,18 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit slurpOptions: SlurpOptions = Set.empty ): F[List[String]] = { val extraEnv = List("GIT_ASKPASS" -> config.gitAskPass.pathAsString) - processAlg.exec(gitCmd ++ args.toList, repo, extraEnv, slurpOptions) + 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]] =