Browse Source

Handle existing clone paths that are not a Git repository

Brendan Abolivier 6 years ago
parent
commit
f33a0f26d7
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 14 additions and 1 deletions
  1. 14
    1
      src/git/git.go

+ 14
- 1
src/git/git.go View File

1
 package git
1
 package git
2
 
2
 
3
 import (
3
 import (
4
+	"fmt"
4
 	"io/ioutil"
5
 	"io/ioutil"
5
 	"os"
6
 	"os"
6
-	"strings"
7
 
7
 
8
 	"config"
8
 	"config"
9
 
9
 
36
 		return
36
 		return
37
 	}
37
 	}
38
 
38
 
39
+	// Check whether the clone path is a Git repository
40
+	var isRepo bool
41
+	if isRepo, err = dirExists(cfg.ClonePath + "/.git"); err != nil {
42
+		return
43
+	} else if exists && !isRepo {
44
+		err = fmt.Errorf(
45
+			"%s already exists but is not a Git repository",
46
+			cfg.ClonePath,
47
+		)
48
+
49
+		return
50
+	}
51
+
39
 	logrus.WithFields(logrus.Fields{
52
 	logrus.WithFields(logrus.Fields{
40
 		"repo":       cfg.User + "@" + cfg.URL,
53
 		"repo":       cfg.User + "@" + cfg.URL,
41
 		"clone_path": cfg.ClonePath,
54
 		"clone_path": cfg.ClonePath,