From 5173d7f5e17fbcab8cf2411abae1e064b076ebbb Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 14 Aug 2022 14:33:44 +1000 Subject: better CLI interface --- pkg/utils/utils.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'pkg/utils') diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 2f33862e8..9d6213c1d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -135,3 +135,30 @@ func FilePath(skip int) string { _, path, _, _ := runtime.Caller(skip) return path } + +// for our cheatsheet script and integration tests. Not to be confused with finding the +// root directory of _any_ random repo. +func GetLazygitRootDirectory() string { + path, err := os.Getwd() + if err != nil { + panic(err) + } + + for { + _, err := os.Stat(filepath.Join(path, ".git")) + + if err == nil { + return path + } + + if !os.IsNotExist(err) { + panic(err) + } + + path = filepath.Dir(path) + + if path == "/" { + log.Fatal("must run in lazygit folder or child folder") + } + } +} -- cgit v1.2.3