Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak committed Nov 21, 2023
1 parent f60e159 commit e8cc2fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 2 additions & 8 deletions pkg/dashboard/server/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/dashboard/worker/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/git/nativeGit/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8cc2fb

Please sign in to comment.