|
|
|
@ -21,6 +21,7 @@ import (
|
|
|
|
stdfs "io/fs"
|
|
|
|
stdfs "io/fs"
|
|
|
|
"log/slog"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"os/exec"
|
|
|
|
"sort"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
@ -95,12 +96,63 @@ func (i *VCSInstaller) Install() error {
|
|
|
|
return fs.CopyDir(i.Repo.LocalPath(), i.Path())
|
|
|
|
return fs.CopyDir(i.Repo.LocalPath(), i.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resetRepo discards all local modifications in the repository.
|
|
|
|
|
|
|
|
// This is used to clean the cached repository before updating.
|
|
|
|
|
|
|
|
func resetRepo(repo vcs.Repo) error {
|
|
|
|
|
|
|
|
// Check the VCS type to determine the appropriate reset command
|
|
|
|
|
|
|
|
switch repo.Vcs() {
|
|
|
|
|
|
|
|
case vcs.Git:
|
|
|
|
|
|
|
|
// For Git, use 'git reset --hard' to discard all local changes
|
|
|
|
|
|
|
|
cmd := exec.Command("git", "reset", "--hard")
|
|
|
|
|
|
|
|
cmd.Dir = repo.LocalPath()
|
|
|
|
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("git reset failed: %w, output: %s", err, output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case vcs.Hg:
|
|
|
|
|
|
|
|
// For Mercurial, use 'hg revert --all --no-backup'
|
|
|
|
|
|
|
|
cmd := exec.Command("hg", "revert", "--all", "--no-backup")
|
|
|
|
|
|
|
|
cmd.Dir = repo.LocalPath()
|
|
|
|
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("hg revert failed: %w, output: %s", err, output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case vcs.Bzr:
|
|
|
|
|
|
|
|
// For Bazaar, use 'bzr revert'
|
|
|
|
|
|
|
|
cmd := exec.Command("bzr", "revert")
|
|
|
|
|
|
|
|
cmd.Dir = repo.LocalPath()
|
|
|
|
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("bzr revert failed: %w, output: %s", err, output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case vcs.Svn:
|
|
|
|
|
|
|
|
// For SVN, use 'svn revert -R .'
|
|
|
|
|
|
|
|
cmd := exec.Command("svn", "revert", "-R", ".")
|
|
|
|
|
|
|
|
cmd.Dir = repo.LocalPath()
|
|
|
|
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("svn revert failed: %w, output: %s", err, output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Errorf("unsupported VCS type: %v", repo.Vcs())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update updates a remote repository
|
|
|
|
// Update updates a remote repository
|
|
|
|
func (i *VCSInstaller) Update() error {
|
|
|
|
func (i *VCSInstaller) Update() error {
|
|
|
|
slog.Debug("updating", "source", i.Repo.Remote())
|
|
|
|
slog.Debug("updating", "source", i.Repo.Remote())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reset any local modifications in the cache directory before updating.
|
|
|
|
|
|
|
|
// The cached repository is managed by Helm and should not contain user modifications.
|
|
|
|
|
|
|
|
// Any modifications made by Helm itself (e.g., to plugin.yaml during installation)
|
|
|
|
|
|
|
|
// should be discarded before attempting to update.
|
|
|
|
if i.Repo.IsDirty() {
|
|
|
|
if i.Repo.IsDirty() {
|
|
|
|
return errors.New("plugin repo was modified")
|
|
|
|
slog.Debug("resetting local modifications in cache", "path", i.Repo.LocalPath())
|
|
|
|
|
|
|
|
if err := resetRepo(i.Repo); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("failed to reset local modifications: %w", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := i.Repo.Update(); err != nil {
|
|
|
|
if err := i.Repo.Update(); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|