summaryrefslogtreecommitdiffstats
path: root/pkg/app
diff options
context:
space:
mode:
authornullishamy <amy.codes@null.net>2022-07-29 23:55:34 +0100
committernullishamy <amy.codes@null.net>2022-07-29 23:55:34 +0100
commit41b54d742f6d5aacfb06174ea527ad33ddcaccec (patch)
treea6b50aad7c180c577c280bddb81833b783a5f364 /pkg/app
parent367b0d331836c90c015bf0c45f88612f3d94d08a (diff)
Check for bare repositories
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/app.go23
1 files changed, 23 insertions, 0 deletions
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
}