ソースを参照

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

Brendan Abolivier 6 年 前
コミット
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