summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-08-14 14:33:44 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-08-14 17:20:52 +1000
commit5173d7f5e17fbcab8cf2411abae1e064b076ebbb (patch)
treec5cc281b56f6b927e5408ec1961bfafd4dea8049 /pkg/utils
parent349a7d24532a32feaaf40129b3b07b9215b8a625 (diff)
better CLI interface
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/utils.go27
1 files changed, 27 insertions, 0 deletions
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")
+ }
+ }
+}