@@ -88,18 +88,18 @@ func ValidateRepositories(repositories []RepositoryPair) {
88
88
}
89
89
}
90
90
91
- func ListRemote (remote * git.Remote , listOptions * git.ListOptions ) ([]* gitplumbing.Reference , error ) {
91
+ func ListRemote (remote * git.Remote , listOptions * git.ListOptions , repository string ) ([]* gitplumbing.Reference , error ) {
92
92
refList , err := remote .List (listOptions )
93
93
if err == gittransport .ErrAuthenticationRequired {
94
94
return nil , backoff .Permanent (err )
95
95
} else if err != nil {
96
- log .Warn ("Retrying listing remote..." )
96
+ log .Warn ("[" , repository , "] Retrying listing remote because the following error occurred: " , err )
97
97
}
98
98
return refList , err
99
99
}
100
100
101
101
// GetBranchesAndTagsFromRemote returns list of branches and tags present in remoteName of repository.
102
- func GetBranchesAndTagsFromRemote (repository * git.Repository , remoteName string , listOptions * git.ListOptions ) ([]string , []string , error ) {
102
+ func GetBranchesAndTagsFromRemote (repository * git.Repository , remoteName string , listOptions * git.ListOptions , sourceRepository string ) ([]string , []string , error ) {
103
103
var branchList []string
104
104
var tagList []string
105
105
var err error
@@ -112,7 +112,7 @@ func GetBranchesAndTagsFromRemote(repository *git.Repository, remoteName string,
112
112
listRemoteBackoff := backoff .NewExponentialBackOff ()
113
113
listRemoteBackoff .MaxElapsedTime = time .Minute
114
114
refList , err := backoff .RetryWithData (
115
- func () ([]* gitplumbing.Reference , error ) { return ListRemote (remote , listOptions ) },
115
+ func () ([]* gitplumbing.Reference , error ) { return ListRemote (remote , listOptions , sourceRepository ) },
116
116
listRemoteBackoff ,
117
117
)
118
118
if err != nil {
@@ -229,32 +229,40 @@ func GetDestinationAuth(destAuth Authentication) *githttp.BasicAuth {
229
229
}
230
230
231
231
// GitPlainClone clones git repository and is retried in case of error.
232
- func GitPlainClone (gitDirectory string , cloneOptions * git.CloneOptions ) (* git.Repository , error ) {
232
+ func GitPlainClone (gitDirectory string , cloneOptions * git.CloneOptions , repositoryName string ) (* git.Repository , error ) {
233
233
repository , err := git .PlainClone (gitDirectory , false , cloneOptions )
234
234
if err == gittransport .ErrAuthenticationRequired {
235
235
// Terminate backoff.
236
236
return nil , backoff .Permanent (err )
237
237
} else if err != nil {
238
- log .Warn ("Retrying cloning repository..." )
238
+ log .Warn ("[" , repositoryName , "] Retrying cloning repository because the following error occurred: " , err )
239
239
}
240
240
return repository , err
241
241
}
242
242
243
243
// GitFetchBranches fetches all branches and is retried in case of error.
244
- func GitFetchBranches (sourceRemote * git.Remote , sourceAuthentication Authentication ) error {
244
+ func GitFetchBranches (sourceRemote * git.Remote , sourceAuthentication Authentication , repositoryName string ) error {
245
245
gitFetchOptions := GetFetchOptions ("refs/heads/*:refs/heads/*" , sourceAuthentication )
246
246
err := sourceRemote .Fetch (gitFetchOptions )
247
- if err == gittransport .ErrAuthenticationRequired {
248
- // Terminate backoff.
247
+ switch err {
248
+ case gittransport .ErrAuthenticationRequired :
249
+ log .Error ("[" , repositoryName , "] Authentication required." )
249
250
return backoff .Permanent (err )
250
- } else if err != nil {
251
- log .Warn ("Retrying fetching branches..." )
251
+ case git .NoErrAlreadyUpToDate :
252
+ // Terminate backoff with no error in case the branch is already up-to-date.
253
+ // This can occur if source or destination repository has only one branch.
254
+ log .Info ("[" , repositoryName , "] Repository up-to-date." )
255
+ return nil
256
+ default :
257
+ if err != nil {
258
+ log .Warn ("[" , repositoryName , "] Retrying fetching branches because the following error occurred: " , err )
259
+ }
260
+ return err
252
261
}
253
- return err
254
262
}
255
263
256
264
// PushRefs pushes refs defined in refSpecString to destination remote and is retried in case of error.
257
- func PushRefs (repository * git.Repository , auth * githttp.BasicAuth , refSpecString string ) error {
265
+ func PushRefs (repository * git.Repository , auth * githttp.BasicAuth , refSpecString string , repositoryName string ) error {
258
266
err := repository .Push (& git.PushOptions {
259
267
RemoteName : "destination" ,
260
268
RefSpecs : []gitconfig.RefSpec {gitconfig .RefSpec (refSpecString )},
@@ -264,7 +272,7 @@ func PushRefs(repository *git.Repository, auth *githttp.BasicAuth, refSpecString
264
272
// Terminate backoff.
265
273
return backoff .Permanent (err )
266
274
} else if err != nil {
267
- log .Warn ("Retrying pushing refs..." )
275
+ log .Warn ("[" , repositoryName , "] Retrying pushing refs because the following error occurred: " , err )
268
276
}
269
277
return err
270
278
}
@@ -283,7 +291,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
283
291
cloneBackoff := backoff .NewExponentialBackOff ()
284
292
cloneBackoff .MaxElapsedTime = 2 * time .Minute
285
293
repository , err := backoff .RetryWithData (
286
- func () (* git.Repository , error ) { return GitPlainClone (gitDirectory , gitCloneOptions ) },
294
+ func () (* git.Repository , error ) { return GitPlainClone (gitDirectory , gitCloneOptions , source ) },
287
295
cloneBackoff ,
288
296
)
289
297
if err != nil {
@@ -293,7 +301,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
293
301
}
294
302
295
303
gitListOptions := GetListOptions (sourceAuthentication )
296
- sourceBranchList , sourceTagList , err := GetBranchesAndTagsFromRemote (repository , "origin" , gitListOptions )
304
+ sourceBranchList , sourceTagList , err := GetBranchesAndTagsFromRemote (repository , "origin" , gitListOptions , source )
297
305
if err != nil {
298
306
ProcessError (err , "getting branches and tags from " , source , & allErrors )
299
307
messages <- MirrorStatus {allErrors , time .Now (), 0 , 0 }
@@ -313,7 +321,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
313
321
fetchBranchesBackoff := backoff .NewExponentialBackOff ()
314
322
fetchBranchesBackoff .MaxElapsedTime = time .Minute
315
323
err = backoff .Retry (
316
- func () error { return GitFetchBranches (sourceRemote , sourceAuthentication ) },
324
+ func () error { return GitFetchBranches (sourceRemote , sourceAuthentication , source ) },
317
325
fetchBranchesBackoff ,
318
326
)
319
327
if err != nil {
@@ -337,7 +345,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
337
345
338
346
destinationAuth := GetDestinationAuth (destinationAuthentication )
339
347
340
- destinationBranchList , destinationTagList , err := GetBranchesAndTagsFromRemote (repository , "destination" , & git.ListOptions {Auth : destinationAuth })
348
+ destinationBranchList , destinationTagList , err := GetBranchesAndTagsFromRemote (repository , "destination" , & git.ListOptions {Auth : destinationAuth }, destination )
341
349
if err != nil {
342
350
ProcessError (err , "getting branches and tags from " , destination , & allErrors )
343
351
}
@@ -351,7 +359,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
351
359
pushBranchesBackoff .MaxElapsedTime = 2 * time .Minute
352
360
err = backoff .Retry (
353
361
func () error {
354
- return PushRefs (repository , destinationAuth , "+" + refBranchPrefix + branch + ":" + refBranchPrefix + branch )
362
+ return PushRefs (repository , destinationAuth , "+" + refBranchPrefix + branch + ":" + refBranchPrefix + branch , destination )
355
363
},
356
364
pushBranchesBackoff ,
357
365
)
@@ -365,7 +373,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
365
373
removeBranchesBackoff := backoff .NewExponentialBackOff ()
366
374
removeBranchesBackoff .MaxElapsedTime = time .Minute
367
375
err = backoff .Retry (
368
- func () error { return PushRefs (repository , destinationAuth , ":" + refBranchPrefix + branch ) },
376
+ func () error { return PushRefs (repository , destinationAuth , ":" + refBranchPrefix + branch , destination ) },
369
377
removeBranchesBackoff ,
370
378
)
371
379
ProcessError (err , "removing branch " + branch + " from " , destination , & allErrors )
@@ -376,7 +384,9 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
376
384
pushTagsBackoff := backoff .NewExponentialBackOff ()
377
385
pushTagsBackoff .MaxElapsedTime = time .Minute
378
386
err = backoff .Retry (
379
- func () error { return PushRefs (repository , destinationAuth , "+" + refTagPrefix + "*:" + refTagPrefix + "*" ) },
387
+ func () error {
388
+ return PushRefs (repository , destinationAuth , "+" + refTagPrefix + "*:" + refTagPrefix + "*" , destination )
389
+ },
380
390
pushTagsBackoff ,
381
391
)
382
392
ProcessError (err , "pushing all tags to " , destination , & allErrors )
@@ -388,7 +398,7 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
388
398
removeTagsBackoff := backoff .NewExponentialBackOff ()
389
399
removeTagsBackoff .MaxElapsedTime = time .Minute
390
400
err = backoff .Retry (
391
- func () error { return PushRefs (repository , destinationAuth , ":" + refTagPrefix + tag ) },
401
+ func () error { return PushRefs (repository , destinationAuth , ":" + refTagPrefix + tag , destination ) },
392
402
removeTagsBackoff ,
393
403
)
394
404
ProcessError (err , "removing tag " + tag + " from " , destination , & allErrors )
0 commit comments