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 2edbcca commit 5bfb8b4
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 164 in modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala

View check run for this annotation

Codecov / codecov/patch

modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala#L162-L164

Added lines #L162 - L164 were not covered by tests
}
}

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

0 comments on commit 5bfb8b4

Please sign in to comment.