From e14ac9359b51f46b228dbc61ac88cf4535726210 Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Mon, 27 Oct 2025 13:47:38 -0700 Subject: [PATCH] fix git reconciler error: worktree contains unstaged changes Signed-off-by: Adam D. Cornett --- internal/reconcilers/pipeline_git_repo.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/reconcilers/pipeline_git_repo.go b/internal/reconcilers/pipeline_git_repo.go index 15502d8..d4a263d 100644 --- a/internal/reconcilers/pipeline_git_repo.go +++ b/internal/reconcilers/pipeline_git_repo.go @@ -109,6 +109,12 @@ func cloneOrPullRepo(targetPath string, pipelineRelease string) (string, error) return "", err } + // Reset the worktree to discard any local changes + // This avoids reconciliation errors when anything other than `main` is used in the CR + if err := w.Reset(&git.ResetOptions{Mode: git.HardReset}); err != nil { + return "", err + } + // Checking out the hash value of the branch/tag that was requested if err := w.Checkout(&git.CheckoutOptions{Hash: ref.Hash()}); err != nil { return "", err