Browse Source

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

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

+ 11
- 8
src/git/git.go View File

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