Parcourir la source

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

Brendan Abolivier il y a 6 ans
Parent
révision
c89381efab
Signé par: Brendan Abolivier <contact@brendanabolivier.com> ID de la clé GPG: 8EF1500759F70623
1 fichiers modifiés avec 11 ajouts et 8 suppressions
  1. 11
    8
      src/git/git.go

+ 11
- 8
src/git/git.go Voir le fichier

12
 	gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
12
 	gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
13
 )
13
 )
14
 
14
 
15
+// Sync
15
 func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
16
 func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
16
 	auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
17
 	auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
17
 	if err != nil {
18
 	if err != nil {
69
 		Auth:       auth,
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
 	return r, err
85
 	return r, err