From 209569af01723522d328b79f9f77a99beecc4f86 Mon Sep 17 00:00:00 2001 From: MrJack <36191829+biagiopietro@users.noreply.github.com> Date: Tue, 16 Dec 2025 15:54:56 +0100 Subject: [PATCH] Revert "feat(plugin): add --version flag to plugin update command" This reverts commit bd37347a0633a38e68b913c45de98f09bbcb8293. Signed-off-by: MrJack <36191829+biagiopietro@users.noreply.github.com> --- internal/plugin/installer/installer.go | 4 +- internal/plugin/installer/vcs_installer.go | 18 +----- .../plugin/installer/vcs_installer_test.go | 63 +------------------ pkg/cmd/plugin_update.go | 10 ++- 4 files changed, 11 insertions(+), 84 deletions(-) diff --git a/internal/plugin/installer/installer.go b/internal/plugin/installer/installer.go index 1f9839054..c7c1a8801 100644 --- a/internal/plugin/installer/installer.go +++ b/internal/plugin/installer/installer.go @@ -160,8 +160,8 @@ func NewForSource(source, version string) (installer Installer, err error) { } // FindSource determines the correct Installer for the given source. -func FindSource(location string, version string) (Installer, error) { - installer, err := existingVCSRepo(location, version) +func FindSource(location string) (Installer, error) { + installer, err := existingVCSRepo(location) if err != nil && err.Error() == "Cannot detect VCS" { slog.Warn("cannot get information about plugin source", "location", location, slog.Any("error", err)) return installer, errors.New("cannot get information about plugin source") diff --git a/internal/plugin/installer/vcs_installer.go b/internal/plugin/installer/vcs_installer.go index 1e858c9ce..3601ec7a8 100644 --- a/internal/plugin/installer/vcs_installer.go +++ b/internal/plugin/installer/vcs_installer.go @@ -38,15 +38,14 @@ type VCSInstaller struct { base } -func existingVCSRepo(location string, version string) (Installer, error) { +func existingVCSRepo(location string) (Installer, error) { repo, err := vcs.NewRepo("", location) if err != nil { return nil, err } i := &VCSInstaller{ - Repo: repo, - Version: version, - base: newBase(repo.Remote()), + Repo: repo, + base: newBase(repo.Remote()), } return i, nil } @@ -105,17 +104,6 @@ func (i *VCSInstaller) Update() error { if err := i.Repo.Update(); err != nil { return err } - - ref, err := i.solveVersion(i.Repo) - if err != nil { - return err - } - if ref != "" { - if err := i.setVersion(i.Repo, ref); err != nil { - return err - } - } - if !isPlugin(i.Repo.LocalPath()) { return ErrMissingMetadata } diff --git a/internal/plugin/installer/vcs_installer_test.go b/internal/plugin/installer/vcs_installer_test.go index 4a6b319cc..d542a0f75 100644 --- a/internal/plugin/installer/vcs_installer_test.go +++ b/internal/plugin/installer/vcs_installer_test.go @@ -48,7 +48,6 @@ func (r *testRepo) UpdateVersion(version string) error { r.current = version return r.err } -func (r *testRepo) IsDirty() bool { return false } func TestVCSInstaller(t *testing.T) { ensure.HelmHome(t) @@ -97,7 +96,7 @@ func TestVCSInstaller(t *testing.T) { } // Testing FindSource method, expect error because plugin code is not a cloned repository - if _, err := FindSource(i.Path(), ""); err == nil { + if _, err := FindSource(i.Path()); err == nil { t.Fatalf("expected error for inability to find plugin source, got none") } else if err.Error() != "cannot get information about plugin source" { t.Fatalf("expected error for inability to find plugin source, got (%v)", err) @@ -159,7 +158,7 @@ func TestVCSInstallerUpdate(t *testing.T) { } // Test FindSource method for positive result - pluginInfo, err := FindSource(i.Path(), "") + pluginInfo, err := FindSource(i.Path()) if err != nil { t.Fatal(err) } @@ -188,61 +187,3 @@ func TestVCSInstallerUpdate(t *testing.T) { } } - -func TestVCSInstallerUpdateWithVersion(t *testing.T) { - ensure.HelmHome(t) - - if err := os.MkdirAll(helmpath.DataPath("plugins"), 0755); err != nil { - t.Fatalf("Could not create %s: %s", helmpath.DataPath("plugins"), err) - } - - source := "https://github.com/adamreese/helm-env" - testRepoPath, _ := filepath.Abs("../testdata/plugdir/good/echo-v1") - repo := &testRepo{ - local: testRepoPath, - remote: source, - tags: []string{"0.1.0", "0.1.1", "0.2.0"}, - } - - // First install without version - i, err := NewForSource(source, "") - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - - vcsInstaller, ok := i.(*VCSInstaller) - if !ok { - t.Fatal("expected a VCSInstaller") - } - vcsInstaller.Repo = repo - - if err := Install(i); err != nil { - t.Fatal(err) - } - - // Now test update with specific version constraint - vcsInstaller.Version = "~0.1.0" - if err := Update(vcsInstaller); err != nil { - t.Fatal(err) - } - if repo.current != "0.1.1" { - t.Fatalf("expected version '0.1.1', got %q", repo.current) - } - - // Test update with different version constraint - vcsInstaller.Version = "0.2.0" - if err := Update(vcsInstaller); err != nil { - t.Fatal(err) - } - if repo.current != "0.2.0" { - t.Fatalf("expected version '0.2.0', got %q", repo.current) - } - - // Test update with non-existent version - vcsInstaller.Version = "0.3.0" - if err := Update(vcsInstaller); err == nil { - t.Fatal("expected error for version does not exist, got none") - } else if err.Error() != fmt.Sprintf("requested version %q does not exist for plugin %q", "0.3.0", source) { - t.Fatalf("expected error for version does not exist, got (%v)", err) - } -} diff --git a/pkg/cmd/plugin_update.go b/pkg/cmd/plugin_update.go index c534f93e9..c6d4b8530 100644 --- a/pkg/cmd/plugin_update.go +++ b/pkg/cmd/plugin_update.go @@ -29,8 +29,7 @@ import ( ) type pluginUpdateOptions struct { - names []string - version string + names []string } func newPluginUpdateCmd(out io.Writer) *cobra.Command { @@ -50,7 +49,6 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command { return o.run(out) }, } - cmd.Flags().StringVar(&o.version, "version", "", "specify a version constraint. If this is not specified, the latest version is installed") return cmd } @@ -73,7 +71,7 @@ func (o *pluginUpdateOptions) run(out io.Writer) error { for _, name := range o.names { if found := findPlugin(plugins, name); found != nil { - if err := updatePlugin(found, o.version); err != nil { + if err := updatePlugin(found); err != nil { errorPlugins = append(errorPlugins, fmt.Errorf("failed to update plugin %s, got error (%v)", name, err)) } else { fmt.Fprintf(out, "Updated plugin: %s\n", name) @@ -88,7 +86,7 @@ func (o *pluginUpdateOptions) run(out io.Writer) error { return nil } -func updatePlugin(p plugin.Plugin, version string) error { +func updatePlugin(p plugin.Plugin) error { exactLocation, err := filepath.EvalSymlinks(p.Dir()) if err != nil { return err @@ -98,7 +96,7 @@ func updatePlugin(p plugin.Plugin, version string) error { return err } - i, err := installer.FindSource(absExactLocation, version) + i, err := installer.FindSource(absExactLocation) if err != nil { return err }