Ver código fonte

Add check on nil error in Push + some more doc

Brendan Abolivier 6 anos atrás
pai
commit
0fa54841f1
Assinado por: Brendan Abolivier <contact@brendanabolivier.com> ID da chave GPG: 8EF1500759F70623
1 arquivos alterados com 13 adições e 7 exclusões
  1. 13
    7
      src/git/git.go

+ 13
- 7
src/git/git.go Ver arquivo

@@ -135,23 +135,29 @@ func dirExists(path string) (bool, error) {
135 135
 // structure instance or pushing to the remote. In the latter case, if the error
136 136
 // is "already up to date" or "non-fast-forward update", doesn't return any error.
137 137
 func Push(r *gogit.Repository, cfg config.GitSettings) error {
138
+	// Get the authentication structure instance
138 139
 	auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
139 140
 	if err != nil {
140 141
 		return err
141 142
 	}
142 143
 
144
+	// Push to remote
143 145
 	err = r.Push(&gogit.PushOptions{
144 146
 		Auth: auth,
145 147
 	})
146 148
 
147
-	if err == gogit.NoErrAlreadyUpToDate {
148
-		return nil
149
-	}
149
+	// Don't return with an error for "already up to date" or "non-fast-forward
150
+	// update"
151
+	if err != nil {
152
+		if err == gogit.NoErrAlreadyUpToDate {
153
+			return nil
154
+		}
150 155
 
151
-	// go-git doesn't have an error variable for "non-fast-forward update", so
152
-	// this is the only way to detect it
153
-	if strings.HasPrefix(err.Error(), "non-fast-forward update") {
154
-		return nil
156
+		// go-git doesn't have an error variable for "non-fast-forward update", so
157
+		// this is the only way to detect it
158
+		if strings.HasPrefix(err.Error(), "non-fast-forward update") {
159
+			return nil
160
+		}
155 161
 	}
156 162
 
157 163
 	return err