From 0d546f78241aaa26d9358bca24e1d83811cb114d Mon Sep 17 00:00:00 2001 From: Urko Date: Wed, 15 Feb 2023 18:13:58 +0100 Subject: [PATCH] feat: get root dir from git command --- pkg/util/path.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pkg/util/path.go diff --git a/pkg/util/path.go b/pkg/util/path.go new file mode 100644 index 0000000..932b9c4 --- /dev/null +++ b/pkg/util/path.go @@ -0,0 +1,18 @@ +package util + +import ( + "log" + "os/exec" + "strings" +) + +func RootDir() string { + cmdOut, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() + if err != nil { + log.Fatalf("exec.Command: %s", err) + return "" + } + + rootDir := strings.TrimSpace(string(cmdOut)) + return rootDir +}