diff --git a/pkg/dashboard/server/releases.go b/pkg/dashboard/server/releases.go index 73450348f..625bd063b 100644 --- a/pkg/dashboard/server/releases.go +++ b/pkg/dashboard/server/releases.go @@ -592,15 +592,9 @@ func delete(w http.ResponseWriter, r *http.Request) { if envFromStore.RepoPerEnv { kustomizationFilePath = filepath.Join("flux", fmt.Sprintf("kustomization-%s.yaml", app)) } - worktree, err := repo.Worktree() + err := nativeGit.DelFile(repo, kustomizationFilePath) if err != nil { - logrus.Errorf("cannot get worktree: %s", err) - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - _, err = worktree.Remove(kustomizationFilePath) - if err != nil { - logrus.Errorf("cannot remove files from the working tree: %s", err) + logrus.Errorf("cannot delete kustomization file: %s", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } diff --git a/pkg/dashboard/worker/gitops.go b/pkg/dashboard/worker/gitops.go index 0bc1344bf..c6501c6e8 100644 --- a/pkg/dashboard/worker/gitops.go +++ b/pkg/dashboard/worker/gitops.go @@ -792,11 +792,7 @@ func cloneTemplateDeleteAndPush( if envFromStore.RepoPerEnv { kustomizationFilePath = filepath.Join("flux", fmt.Sprintf("kustomization-%s.yaml", cleanupPolicy.AppToCleanup)) } - worktree, err := repo.Worktree() - if err != nil { - return "", err - } - _, err = worktree.Remove(kustomizationFilePath) + err := nativeGit.DelFile(repo, kustomizationFilePath) if err != nil { return "", err } diff --git a/pkg/git/nativeGit/helper.go b/pkg/git/nativeGit/helper.go index 8355c5133..0c8adf1b9 100644 --- a/pkg/git/nativeGit/helper.go +++ b/pkg/git/nativeGit/helper.go @@ -417,6 +417,17 @@ func DelDir(repo *git.Repository, path string) error { return err } +func DelFile(repo *git.Repository, filePath string) error { + worktree, err := repo.Worktree() + if err != nil { + return err + } + + _, err = worktree.Remove(filePath) + + return err +} + func StageFolder(repo *git.Repository, folder string) error { worktree, err := repo.Worktree() if err != nil {