From 8b1b024f51b166bf29481162fa57e5752d0d9300 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 23 Jan 2025 07:43:07 -0500 Subject: [PATCH] fix(golang-rewrite): allow missing post-plugin-update callback during plugin update (#1849) --- docs/guide/upgrading-from-v0-15-to-v0-16.md | 5 ----- docs/plugins/create.md | 2 +- internal/plugins/plugins.go | 5 ++++- internal/plugins/plugins_test.go | 14 +++++++++++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/guide/upgrading-from-v0-15-to-v0-16.md b/docs/guide/upgrading-from-v0-15-to-v0-16.md index 7734031f2..8b1bbccf8 100644 --- a/docs/guide/upgrading-from-v0-15-to-v0-16.md +++ b/docs/guide/upgrading-from-v0-15-to-v0-16.md @@ -8,11 +8,6 @@ rather than a set of scripts. ## Breaking Changes -### `download` is now a required callback for plugins - -Previously `download` was optional, now it is required. If a plugin lacks this -callback any installs of any version of that plugin will fail. - ### Hyphenated commands have been removed asdf version 0.15.0 and earlier supported by hyphenated and non-hyphenated diff --git a/docs/plugins/create.md b/docs/plugins/create.md index 4a9a40244..7a34fa36f 100644 --- a/docs/plugins/create.md +++ b/docs/plugins/create.md @@ -34,7 +34,7 @@ The full list of scripts callable from asdf. | Script | Description | | :---------------------------------------------------------------------------------------------------- |:-----------------------------------------------------------------| | [bin/list-all](#bin-list-all) | List all installable versions | -| [bin/download](#bin-download) | Download source code or binary for the specified version | +| [bin/download](#bin-download) | Download source code or binary for the specified version | | [bin/install](#bin-install) | Installs the specified version | | [bin/latest-stable](#bin-latest-stable) | List the latest stable version of the specified tool | | [bin/help.overview](#bin-help.overview) | Output a general description about the plugin & tool | diff --git a/internal/plugins/plugins.go b/internal/plugins/plugins.go index cdade53f9..1d4c7255f 100644 --- a/internal/plugins/plugins.go +++ b/internal/plugins/plugins.go @@ -261,11 +261,14 @@ func (p Plugin) Update(conf config.Config, ref string, out, errout io.Writer) (s } err = p.RunCallback("post-plugin-update", []string{}, env, out, errout) + if _, ok := err.(NoCallbackError); err != nil && !ok { + return newRef, err + } hook.Run(conf, "post_asdf_plugin_update", []string{p.Name}) hook.Run(conf, fmt.Sprintf("post_asdf_plugin_update_%s", p.Name), []string{}) - return newRef, err + return newRef, nil } // List takes config and flags for what to return and builds a list of plugins diff --git a/internal/plugins/plugins_test.go b/internal/plugins/plugins_test.go index af2372a93..8b12270f4 100644 --- a/internal/plugins/plugins_test.go +++ b/internal/plugins/plugins_test.go @@ -231,9 +231,13 @@ func TestUpdate(t *testing.T) { repoPath, err := repotest.GeneratePlugin("dummy_plugin", testDataDir, testPluginName) assert.Nil(t, err) + assert.Nil(t, Add(conf, testPluginName, repoPath, "")) - err = Add(conf, testPluginName, repoPath, "") + noPostUpdateCallbackPlugin := "no-post-update" + repoPath, err = repotest.GeneratePlugin("dummy_plugin", testDataDir, noPostUpdateCallbackPlugin) assert.Nil(t, err) + assert.Nil(t, os.Remove(filepath.Join(repoPath, "bin", "post-plugin-update"))) + assert.Nil(t, Add(conf, noPostUpdateCallbackPlugin, repoPath, "")) badPluginName := "badplugin" badRepo := data.PluginDirectory(testDataDir, badPluginName) @@ -272,6 +276,14 @@ func TestUpdate(t *testing.T) { wantSomeRef: true, wantErrMsg: "", }, + { + desc: "updates plugin when plugin when post-plugin-update callback does not exist", + givenConf: conf, + givenName: noPostUpdateCallbackPlugin, + givenRef: "", + wantSomeRef: true, + wantErrMsg: "", + }, } for _, tt := range tests {