Skip to content

Commit

Permalink
feat: toggle off repo sync completely (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus committed Aug 3, 2021
1 parent 7697e6e commit a3ba5a7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
48 changes: 41 additions & 7 deletions docs/manage/configuration.md
Expand Up @@ -25,6 +25,7 @@ The versions can be in the following format:
- `system` - this keyword causes asdf to passthrough to the version of the tool on the system that is not managed by asdf.

::: tip

Multiple versions can be set by separating them with a space. For example, to use Python `3.7.2`, fallback to Python `2.7.15` and finally to the `system` Python, the following line can be added to `.tool-versions`.

```:no-line-numbers
Expand All @@ -41,18 +42,51 @@ Edit the file directly or use `asdf local` (or `asdf global`) which updates it.

## `$HOME/.asdfrc`

Add a `.asdfrc` file to your home directory and asdf will use the settings specified in the file. The file should be formatted like this:
Add an `.asdfrc` file to your home directory and asdf will use the settings specified in the file. The file below shows the required format with the default values to demonstrate:

```:no-line-numbers
legacy_version_file = yes
legacy_version_file = no
use_release_candidates = no
always_keep_download = no
plugin_repository_last_check_duration = 60
```

**Settings**
### `legacy_version_file`

Plugins **with support** can read the versions files used by other version managers, for example, `.ruby-version` in the case of Ruby's `rbenv`.

| Options | Description |
| :--------------------------------------------------------- | :------------------------------------------------------------------------- |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Use `.tool-versions` to read versions |
| `yes` | Use plugin fallback to legacy version files (`.ruby-version`) if available |

### `use_release_candidates`

Configure the `asdf update` command to upgrade to the latest Release Candidate instead of the latest Semantic Version.

| Options | Description |
| :--------------------------------------------------------- | :------------------------ |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Semantic Version is used |
| `yes` | Release Candidate is used |

### `always_keep_download`

Configure the `asdf install` command to keep or delete the source code or binary it downloads.

| Options | Description |
| :--------------------------------------------------------- | :---------------------------------------------------- |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Delete source code or binary after successful install |
| `yes` | Keep source code or binary after install |

### `plugin_repository_last_check_duration`

Configure the duration since the last asdf plugin repository sync to the next. Commands `asdf plugin add <name>` or `asdf plugin list all` will trigger a check of the duration, if the duration has passed then a sync occurs.

- `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.
| Options | Description |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- |
| integer in range `1` to `999999999` <br/> `60` is <Badge type="tip" text="default" vertical="middle" /> | Sync on trigger event if duration since last sync has passed |
| `0` | Sync on each trigger event |
| `never` | Never sync |

## Environment Variables

Expand Down
24 changes: 16 additions & 8 deletions lib/utils.bash
Expand Up @@ -379,17 +379,25 @@ get_asdf_config_value() {
get_asdf_config_value_from_file "$default_config_path" "$key"
}

# Whether the plugin shortname repo needs to be synced
# 0: if no sync needs to occur
# 1: if sync needs to occur
repository_needs_update() {
local update_file_dir
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 plugin_repository_last_check_duration setting.
local plugin_repository_last_check_duration
local sync_required

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 -mmin +"${plugin_repository_last_check_duration:-60}" -print)
[ -n "$find_result" ]

if [ "never" != "$plugin_repository_last_check_duration" ]; then
local update_file_dir
local update_file_name
update_file_dir="$(asdf_data_dir)/tmp"
update_file_name="repo-updated"
# `find` outputs filename if it has not been modified in plugin_repository_last_check_duration setting.
sync_required=$(find "$update_file_dir" -name "$update_file_name" -type f -mmin +"${plugin_repository_last_check_duration:-60}" -print)
fi

[ "$sync_required" ]
}

initialize_or_update_repository() {
Expand Down
13 changes: 13 additions & 0 deletions test/plugin_list_all_command.bats
Expand Up @@ -38,12 +38,25 @@ foo http://example.com/foo"
[ "$output" = "$expected" ]
}

@test "plugin_list_all skips repo sync because check_duration is set to never" {
echo 'plugin_repository_last_check_duration = never' > $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="\
bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo"

[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}

0 comments on commit a3ba5a7

Please sign in to comment.