Skip to content

Commit

Permalink
feat: configurable plugin repo last check time (#957)
Browse files Browse the repository at this point in the history
Co-authored-by: James Hegedus <jthegedus@hey.com>
  • Loading branch information
NeoHsu and jthegedus committed Jun 2, 2021
1 parent 7ad3011 commit 1716afa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/core-configuration.md
Expand Up @@ -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 <name>`, `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

Expand Down
6 changes: 4 additions & 2 deletions lib/utils.bash
Expand Up @@ -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" ]
}

Expand Down
26 changes: 26 additions & 0 deletions test/plugin_list_all_command.bats
Expand Up @@ -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="\
Expand Down

0 comments on commit 1716afa

Please sign in to comment.