From 1716afa02125aa322d8a688ff4b3e95f2e08b33c Mon Sep 17 00:00:00 2001 From: Neo Hsu Date: Wed, 2 Jun 2021 12:22:27 +0800 Subject: [PATCH] feat: configurable plugin repo last check time (#957) Co-authored-by: James Hegedus --- docs/core-configuration.md | 1 + lib/utils.bash | 6 ++++-- test/plugin_list_all_command.bats | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/core-configuration.md b/docs/core-configuration.md index 54a67ffaf..2b63648e6 100644 --- a/docs/core-configuration.md +++ b/docs/core-configuration.md @@ -45,6 +45,7 @@ legacy_version_file = yes - `legacy_version_file` - defaults to `no`. If set to yes it will cause plugins that support this feature to read the version files used by other version managers (e.g. `.ruby-version` in the case of Ruby's `rbenv`). - `use_release_candidates` - defaults to `no`. If set to yes it will cause the `asdf update` command to upgrade to the latest release candidate release instead of the latest semantic version. - `always_keep_download` - defaults to `no`. If set to `yes` it will cause `asdf install` always keep the source code or binary it downloads. If set to `no` the source code or binary downloaded by `asdf install` will be deleted after successful installation. +- `plugin_repository_last_check_duration` - defaults to `60` mins (1 hrs). It will set asdf plugins repository last check duration. When `asdf plugin add `, `asdf plugin list all` command be executed, it will check last update duration to update repository. If set to `0` it will update asdf plugins repository every time. ## Environment Variables diff --git a/lib/utils.bash b/lib/utils.bash index 58757d660..8b2f1ad32 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -384,9 +384,11 @@ repository_needs_update() { update_file_dir="$(asdf_data_dir)/tmp" local update_file_name update_file_name="repo-updated" - # `find` outputs filename if it has not been modified in the last day + # `find` outputs filename if it has not been modified in plugin_repository_last_check_duration setting. + local plugin_repository_last_check_duration + plugin_repository_last_check_duration="$(get_asdf_config_value "plugin_repository_last_check_duration")" local find_result - find_result=$(find "$update_file_dir" -name "$update_file_name" -type f -mtime +1 -print) + find_result=$(find "$update_file_dir" -name "$update_file_name" -type f -mmin +"${plugin_repository_last_check_duration:-60}" -print) [ -n "$find_result" ] } diff --git a/test/plugin_list_all_command.bats b/test/plugin_list_all_command.bats index 9d43744c4..6148cd0a6 100644 --- a/test/plugin_list_all_command.bats +++ b/test/plugin_list_all_command.bats @@ -12,6 +12,32 @@ teardown() { clean_asdf_dir } +@test "plugin_list_all should sync repo when check_duration set to 0" { + echo 'plugin_repository_last_check_duration = 0' > $HOME/.asdfrc + run asdf plugin-list-all + local expected_plugin_repo_sync="updating plugin repository..." + local expected_plugins_list="\ +bar http://example.com/bar +dummy *http://example.com/dummy +foo http://example.com/foo" + + [ "$status" -eq 0 ] + [[ "$output" =~ "$expected_plugin_repo_sync" ]] + [[ "$output" =~ "$expected_plugins_list" ]] +} + +@test "plugin_list_all no immediate repo sync expected because check_duration is greater than 0" { + echo 'plugin_repository_last_check_duration = 10' > $HOME/.asdfrc + run asdf plugin-list-all + local expected="\ +bar http://example.com/bar +dummy *http://example.com/dummy +foo http://example.com/foo" + + [ "$status" -eq 0 ] + [ "$output" = "$expected" ] +} + @test "plugin_list_all list all plugins in the repository" { run asdf plugin-list-all local expected="\