|
|
|
|
84
|
// remote using a given auth, in order to be up to date with the remote.
|
84
|
// remote using a given auth, in order to be up to date with the remote.
|
85
|
// Returns with the go-git representation of the repository.
|
85
|
// Returns with the go-git representation of the repository.
|
86
|
// Returns an error if there was an issue opening the repo, getting its work
|
86
|
// Returns an error if there was an issue opening the repo, getting its work
|
87
|
-// tree or pulling from the remote. In the latter case, if the error is "already
|
|
|
88
|
-// up to date", "non-fast-forward update" or "remote repository is empty",
|
|
|
89
|
-// doesn't return any error.
|
|
|
|
|
87
|
+// tree or pulling from the remote. In the latter case, if the error is a known
|
|
|
88
|
+// non-error, doesn't return any error.
|
90
|
func pull(clonePath string, auth *gitssh.PublicKeys) (*gogit.Repository, error) {
|
89
|
func pull(clonePath string, auth *gitssh.PublicKeys) (*gogit.Repository, error) {
|
91
|
// Open the repository
|
90
|
// Open the repository
|
92
|
r, err := gogit.PlainOpen(clonePath)
|
91
|
r, err := gogit.PlainOpen(clonePath)
|
|
|
|
|
134
|
// created from the configuration to authenticate on the remote.
|
133
|
// created from the configuration to authenticate on the remote.
|
135
|
// Returns with an error if there was an issue creating the authentication
|
134
|
// Returns with an error if there was an issue creating the authentication
|
136
|
// structure instance or pushing to the remote. In the latter case, if the error
|
135
|
// structure instance or pushing to the remote. In the latter case, if the error
|
137
|
-// is "already up to date", "non-fast-forward update" or "remote repository is
|
|
|
138
|
-// empty", doesn't return any error.
|
|
|
|
|
136
|
+// is a known non-error, doesn't return any error.
|
139
|
func Push(r *gogit.Repository, cfg config.GitSettings) error {
|
137
|
func Push(r *gogit.Repository, cfg config.GitSettings) error {
|
140
|
// Get the authentication structure instance
|
138
|
// Get the authentication structure instance
|
141
|
auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
|
139
|
auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
|
|
|
|
|
166
|
// processRemoteErrors checks an error against known non-errors returned when
|
164
|
// processRemoteErrors checks an error against known non-errors returned when
|
167
|
// communicating with the remote. If the error is a non-error, returns nil and
|
165
|
// communicating with the remote. If the error is a non-error, returns nil and
|
168
|
// logs it with the provided fields. If not, returns the error.
|
166
|
// logs it with the provided fields. If not, returns the error.
|
|
|
167
|
+// Current known non-errors are "already up to date" and "remote repository is
|
|
|
168
|
+// empty".
|
169
|
func checkRemoteErrors(err error, logFields logrus.Fields) error {
|
169
|
func checkRemoteErrors(err error, logFields logrus.Fields) error {
|
170
|
var nonError bool
|
170
|
var nonError bool
|
171
|
|
171
|
|
|
|
|
|
182
|
break
|
182
|
break
|
183
|
}
|
183
|
}
|
184
|
|
184
|
|
185
|
- // go-git doesn't have an error variable for "non-fast-forward update", so
|
|
|
186
|
- // this is the only way to detect it
|
|
|
187
|
- if strings.HasPrefix(err.Error(), "non-fast-forward update") {
|
|
|
188
|
- nonError = true
|
|
|
189
|
- }
|
|
|
190
|
-
|
|
|
191
|
// Log non-error
|
185
|
// Log non-error
|
192
|
if nonError {
|
186
|
if nonError {
|
193
|
logrus.WithFields(logFields).Warn("Caught specific non-error")
|
187
|
logrus.WithFields(logFields).Warn("Caught specific non-error")
|