瀏覽代碼

Handle existing clone paths that are not a Git repository

Brendan Abolivier 6 年之前
父節點
當前提交
f33a0f26d7
簽署人: Brendan Abolivier <contact@brendanabolivier.com> GPG 金鑰 ID: 8EF1500759F70623
共有 1 個文件被更改,包括 14 次插入1 次删除
  1. 14
    1
      src/git/git.go

+ 14
- 1
src/git/git.go 查看文件

@@ -1,9 +1,9 @@
1 1
 package git
2 2
 
3 3
 import (
4
+	"fmt"
4 5
 	"io/ioutil"
5 6
 	"os"
6
-	"strings"
7 7
 
8 8
 	"config"
9 9
 
@@ -36,6 +36,19 @@ func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
36 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 52
 	logrus.WithFields(logrus.Fields{
40 53
 		"repo":       cfg.User + "@" + cfg.URL,
41 54
 		"clone_path": cfg.ClonePath,