Browse Source

Handle the case where there is no git dir without panic

Simon Watson 11 months ago
parent
commit
bd531004ef
1 changed files with 3 additions and 2 deletions
  1. 3 2
      pest.go

+ 3 - 2
pest.go

@@ -90,7 +90,8 @@ func parseTomlFromFile(filePath string) (PestConfig, error) {
 func gitGetHead(filePath string) (string, string) {
 func gitGetHead(filePath string) (string, string) {
 	gitObj, err := git.PlainOpen(filePath)
 	gitObj, err := git.PlainOpen(filePath)
 	if err != nil {
 	if err != nil {
-		panic(err)
+		// Likely not a git dir, return empty
+		return "", ""
 	}
 	}
 
 
 	headRef, err := gitObj.Head()
 	headRef, err := gitObj.Head()
@@ -209,7 +210,7 @@ func assemble_prompt(config *PestConfig) {
 
 
 func main() {
 func main() {
 
 
-	toml, err := parseTomlFromFile("./pest.cfg")
+	toml, err := parseTomlFromFile("/home/swatson/Repos/go-pest/pest.cfg")
 	if err != nil {
 	if err != nil {
 		fmt.Println("Couldn't parse TOML const!")
 		fmt.Println("Couldn't parse TOML const!")
 	}
 	}