From 41b54d742f6d5aacfb06174ea527ad33ddcaccec Mon Sep 17 00:00:00 2001 From: nullishamy Date: Fri, 29 Jul 2022 23:55:34 +0100 Subject: [PATCH] Check for bare repositories --- pkg/app/app.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/app/app.go b/pkg/app/app.go index 9a7b1ffcc..265b5caaf 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -151,6 +151,17 @@ func isDirectoryAGitRepository(dir string) (bool, error) { return info != nil && info.IsDir(), err } +func isBareRepo(osCommand *oscommands.OSCommand) (bool, error) { + res, err := osCommand.Cmd.New("git rev-parse --is-bare-repository").DontLog().RunWithOutput() + + if err != nil { + return false, err + } + + // The command returns output with a newline, so we need to strip + return strconv.ParseBool(strings.TrimSpace(res)) +} + func (app *App) setupRepo() (bool, error) { if err := app.validateGitVersion(); err != nil { return false, err @@ -167,6 +178,7 @@ func (app *App) setupRepo() (bool, error) { if err != nil { return false, err } + if isRepo, err := isDirectoryAGitRepository(cwd); isRepo { return false, err } @@ -210,6 +222,17 @@ func (app *App) setupRepo() (bool, error) { } } + // Run this afterward so that the previous repo creation steps can run without this interfering + if isBare, err := isBareRepo(app.OSCommand); isBare { + if err != nil { + return false, err + } + + if isBare { + log.Fatalln("bare repositories are not supported by lazygit, please make this a working repository.") + } + } + return false, nil }