@@ -227,16 +227,22 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
227227 return failWithError (err )
228228 }
229229
230+ // Use the git operations timeout for the repo.
231+ cloneCtx , cancel := context .WithTimeout (ctx , origin .Spec .Timeout .Duration )
232+ defer cancel ()
230233 var repo * gogit.Repository
231- if repo , err = cloneInto (ctx , access , ref , tmp ); err != nil {
234+ if repo , err = cloneInto (cloneCtx , access , ref , tmp ); err != nil {
232235 return failWithError (err )
233236 }
234237
235238 // When there's a push spec, the pushed-to branch is where commits
236239 // shall be made
237240
238241 if gitSpec .Push != nil {
239- if err := fetch (ctx , tmp , pushBranch , access ); err != nil && err != errRemoteBranchMissing {
242+ // Use the git operations timeout for the repo.
243+ fetchCtx , cancel := context .WithTimeout (ctx , origin .Spec .Timeout .Duration )
244+ defer cancel ()
245+ if err := fetch (fetchCtx , tmp , pushBranch , access ); err != nil && err != errRemoteBranchMissing {
240246 return failWithError (err )
241247 }
242248 if err = switchBranch (repo , pushBranch ); err != nil {
@@ -320,7 +326,10 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
320326 return failWithError (err )
321327 }
322328 } else {
323- if err := push (ctx , tmp , pushBranch , access ); err != nil {
329+ // Use the git operations timeout for the repo.
330+ pushCtx , cancel := context .WithTimeout (ctx , origin .Spec .Timeout .Duration )
331+ defer cancel ()
332+ if err := push (pushCtx , tmp , pushBranch , access ); err != nil {
324333 return failWithError (err )
325334 }
326335
@@ -475,8 +484,8 @@ func (r *ImageUpdateAutomationReconciler) getRepoAccess(ctx context.Context, rep
475484 return access , nil
476485}
477486
478- func (r repoAccess ) remoteCallbacks () libgit2.RemoteCallbacks {
479- return gitlibgit2 .RemoteCallbacks (r .auth )
487+ func (r repoAccess ) remoteCallbacks (ctx context. Context ) libgit2.RemoteCallbacks {
488+ return gitlibgit2 .RemoteCallbacks (ctx , r .auth )
480489}
481490
482491// cloneInto clones the upstream repository at the `ref` given (which
@@ -637,7 +646,7 @@ func fetch(ctx context.Context, path string, branch string, access repoAccess) e
637646 err = origin .Fetch (
638647 []string {refspec },
639648 & libgit2.FetchOptions {
640- RemoteCallbacks : access .remoteCallbacks (),
649+ RemoteCallbacks : access .remoteCallbacks (ctx ),
641650 }, "" ,
642651 )
643652 if err != nil && libgit2 .IsErrorCode (err , libgit2 .ErrorCodeNotFound ) {
@@ -662,7 +671,7 @@ func push(ctx context.Context, path, branch string, access repoAccess) error {
662671 }
663672 defer origin .Free ()
664673
665- callbacks := access .remoteCallbacks ()
674+ callbacks := access .remoteCallbacks (ctx )
666675
667676 // calling repo.Push will succeed even if a reference update is
668677 // rejected; to detect this case, this callback is supplied.
0 commit comments