feat: get root dir from git

This commit is contained in:
Urko 2023-02-26 09:35:06 +01:00
commit b48e967e09
2 changed files with 21 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.urkob.com/urk/go-root-dir
go 1.19

18
main.go Normal file
View File

@ -0,0 +1,18 @@
package main
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
}