Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable short-name repository with config value #1227

Merged
1 change: 1 addition & 0 deletions defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# enables the use of .ruby-version like files used by other version managers
legacy_version_file = no
asdf_repository_url = https://github.com/asdf-vm/asdf-plugins.git
14 changes: 14 additions & 0 deletions docs/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ legacy_version_file = no
use_release_candidates = no
always_keep_download = no
plugin_repository_last_check_duration = 60
asdf_repository_url = https://github.com/asdf-vm/asdf-plugins.git
```

### `legacy_version_file`
Expand Down Expand Up @@ -96,6 +97,19 @@ Configure the duration since the last asdf plugin repository sync to the next. C
| `0` | Sync on each trigger event |
| `never` | Never sync |

### `asdf_repository_url`

::: warning Note
Custom short-name plugin repositories are not supported
:::

Configure the url of the short-name repository. Commands `asdf plugin add <name>` or `asdf plugin list all` will trigger a clone of the repository, if a value is set.

| Options | Description |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- |
| Git URL of a short-name repository | Clone this repository if installing plugins without URL |
| `` | Disable short-name plugin repository. |

## Environment Variables

- `ASDF_CONFIG_FILE` - Defaults to `~/.asdfrc` as described above. Can be set to any location.
Expand Down
4 changes: 4 additions & 0 deletions docs/manage/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Removing a plugin will remove all installations of the tool made with the plugin

## Syncing the Short-name Repository

::: tip Recommendation
The short-name repo can be disabled by removing `asdf_repository_url` from the default configuration file.
:::

The short-name repo is synced to your local machine and periodically refreshed. This period is determined by the following method:

- commands `asdf plugin add <name>` or `asdf plugin list all` can trigger a sync
Expand Down
10 changes: 5 additions & 5 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ asdf_dir() {
printf "%s\\n" "$ASDF_DIR"
}

asdf_repository_url() {
printf "https://github.com/asdf-vm/asdf-plugins.git\\n"
}

asdf_data_dir() {
local data_dir

Expand Down Expand Up @@ -404,7 +400,11 @@ initialize_or_update_repository() {
local repository_url
local repository_path

repository_url=$(asdf_repository_url)
repository_url="$(get_asdf_config_value "asdf_repository_url")"
if [ ! -z "$repository_url" ]; then
jrbeverly marked this conversation as resolved.
Show resolved Hide resolved
printf "No short-name plugin repository in configuration\\n" >&2
exit 1
fi
repository_path=$(asdf_data_dir)/repository

if [ ! -d "$repository_path" ]; then
Expand Down
29 changes: 29 additions & 0 deletions test/plugin_add_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ teardown() {
[ "$output" = "elixir" ]
}

@test "plugin_add command with no URL specified adds a plugin using repo from config" {
export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults
echo "" > $ASDF_CONFIG_DEFAULT_FILE

export ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc
cat > $ASDF_CONFIG_FILE <<-EOM
asdf_repository_url = https://github.com/asdf-vm/asdf-plugins.git
EOM

run asdf plugin add "elixir"
[ "$status" -eq 0 ]

run asdf plugin-list
# whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "elixir" ]
}

@test "plugin_add command with no URL specified fails to add a plugin when no default repo" {
export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults
echo "" > $ASDF_CONFIG_DEFAULT_FILE

export ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc
echo "" > $ASDF_CONFIG_FILE

run asdf plugin add "elixir"
[ "$status" -eq 1 ]
[ "$output" = "No short-name plugin repository in configuration" ]
}

@test "plugin_add command with URL specified adds a plugin using repo" {
install_mock_plugin_repo "dummy"

Expand Down