Skip to content

Commit 4f00f59

Browse files
committed
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.
1 parent 97598b6 commit 4f00f59

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

modules/core/src/main/scala/org/scalasteward/core/git/FileGitAlg.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,18 @@ final class FileGitAlg[F[_]](config: GitCfg)(implicit
151151
slurpOptions: SlurpOptions = Set.empty
152152
): F[List[String]] = {
153153
val extraEnv = List("GIT_ASKPASS" -> config.gitAskPass.pathAsString)
154-
processAlg.exec(gitCmd ++ args.toList, repo, extraEnv, slurpOptions)
154+
processAlg
155+
.exec(gitCmd ++ args.toList, repo, extraEnv, slurpOptions)
156+
.recoverWith {
157+
case ex: ProcessFailedException
158+
if ex.getMessage.contains("fatal: not in a git directory") =>
159+
// `git status` prints a more informative error message than some other git commands, like `git config`
160+
// this will hopefully print that error message to the logs in addition to the actual failure
161+
processAlg
162+
.exec(Nel.of("git", "status"), repo, List.empty, slurpOptions)
163+
.attempt
164+
.void >> ex.raiseError
165+
}
155166
}
156167

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

0 commit comments

Comments
 (0)