浏览代码

Check if err isn't nil to avoid nil pointer dereference

父节点
当前提交
c89381efab
签署人:: Brendan Abolivier <contact@brendanabolivier.com> GPG 密钥 ID: 8EF1500759F70623
共有 1 个文件被更改,包括 11 次插入8 次删除
  1. 11
    8
      src/git/git.go

+ 11
- 8
src/git/git.go 查看文件

@@ -12,6 +12,7 @@ import (
12 12
 	gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
13 13
 )
14 14
 
15
+// Sync
15 16
 func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
16 17
 	auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
17 18
 	if err != nil {
@@ -69,14 +70,16 @@ func pull(clonePath string, auth *gitssh.PublicKeys) (*gogit.Repository, error)
69 70
 		Auth:       auth,
70 71
 	})
71 72
 
72
-	if err == gogit.NoErrAlreadyUpToDate {
73
-		return r, nil
74
-	}
75
-
76
-	// go-git doesn't have an error variable for "non-fast-forward update", so
77
-	// this is the only way to detect it
78
-	if strings.HasPrefix(err.Error(), "non-fast-forward update") {
79
-		return r, nil
73
+	if err != nil {
74
+		if err == gogit.NoErrAlreadyUpToDate {
75
+			return r, nil
76
+		}
77
+
78
+		// go-git doesn't have an error variable for "non-fast-forward update",
79
+		// so this is the only way to detect it
80
+		if strings.HasPrefix(err.Error(), "non-fast-forward update") {
81
+			return r, nil
82
+		}
80 83
 	}
81 84
 
82 85
 	return r, err