diff --git a/help.txt b/help.txt index f2158e8e3..1701c5783 100644 --- a/help.txt +++ b/help.txt @@ -1,64 +1,66 @@ MANAGE PLUGINS -asdf plugin add [] Add a plugin from the plugin repo OR, - add a Git repo as a plugin by - specifying the name and repo url -asdf plugin list [--urls] [--refs] List installed plugins. Optionally show - git urls and git-ref -asdf plugin list all List plugins registered on asdf-plugins - repository with URLs -asdf plugin remove Remove plugin and package versions -asdf plugin update [] Update a plugin to latest commit on - default branch or a particular git-ref -asdf plugin update --all Update all plugins to latest commit on - default branch +asdf plugin add [] [] Add a plugin from the plugin repo OR, + add a Git repo as a plugin by + specifying the name and repo url. + It's also possible to specify a particular + branch/tag by using the git-ref argument. +asdf plugin list [--urls] [--refs] List installed plugins. Optionally show + git urls and git-ref +asdf plugin list all List plugins registered on asdf-plugins + repository with URLs +asdf plugin remove Remove plugin and package versions +asdf plugin update [] Update a plugin to latest commit on + default branch or a particular git-ref +asdf plugin update --all Update all plugins to latest commit on + default branch MANAGE PACKAGES -asdf install Install all the package versions listed - in the .tool-versions file -asdf install Install one tool at the version - specified in the .tool-versions file -asdf install Install a specific version of a package -asdf install latest[:] Install the latest stable version of a - package, or with optional version, - install the latest stable version that - begins with the given string -asdf uninstall Remove a specific version of a package -asdf current Display current version set or being - used for all packages -asdf current Display current version set or being - used for package -asdf where [] Display install path for an installed - or current version -asdf which Display the path to an executable -asdf local Set the package local version -asdf local latest[:] Set the package local version to the - latest provided version -asdf global Set the package global version -asdf global latest[:] Set the package global version to the - latest provided version -asdf shell Set the package version to - `ASDF_${LANG}_VERSION` in the current shell -asdf latest [] Show latest stable version of a package -asdf latest --all Show latest stable version of all the - packages and if they are installed -asdf list [version] List installed versions of a package and - optionally filter the versions -asdf list all [] List all versions of a package and - optionally filter the returned versions -asdf help [] Output documentation for plugin and tool +asdf install Install all the package versions listed + in the .tool-versions file +asdf install Install one tool at the version + specified in the .tool-versions file +asdf install Install a specific version of a package +asdf install latest[:] Install the latest stable version of a + package, or with optional version, + install the latest stable version that + begins with the given string +asdf uninstall Remove a specific version of a package +asdf current Display current version set or being + used for all packages +asdf current Display current version set or being + used for package +asdf where [] Display install path for an installed + or current version +asdf which Display the path to an executable +asdf local Set the package local version +asdf local latest[:] Set the package local version to the + latest provided version +asdf global Set the package global version +asdf global latest[:] Set the package global version to the + latest provided version +asdf shell Set the package version to + `ASDF_${LANG}_VERSION` in the current shell +asdf latest [] Show latest stable version of a package +asdf latest --all Show latest stable version of all the + packages and if they are installed +asdf list [version] List installed versions of a package and + optionally filter the versions +asdf list all [] List all versions of a package and + optionally filter the returned versions +asdf help [] Output documentation for plugin and tool UTILS -asdf exec [args...] Executes the command shim for current version -asdf env [util] Runs util (default: `env`) inside the - environment used for command shim execution. -asdf info Print OS, Shell and ASDF debug information. -asdf reshim Recreate shims for version of a package -asdf shim-versions List the plugins and versions that - provide a command -asdf update Update asdf to the latest stable release -asdf update --head Update asdf to the latest on the master branch +asdf exec [args...] Executes the command shim for current version +asdf env [util] Runs util (default: `env`) inside the + environment used for command shim execution. +asdf info Print OS, Shell and ASDF debug information. +asdf reshim Recreate shims for version of a package +asdf shim-versions List the plugins and versions that + provide a command +asdf update Update asdf to the latest stable release +asdf update --head Update asdf to the latest on the master branch RESOURCES GitHub: https://github.com/asdf-vm/asdf diff --git a/lib/commands/command-plugin-add.bash b/lib/commands/command-plugin-add.bash index 0f4685a68..f03da15d6 100644 --- a/lib/commands/command-plugin-add.bash +++ b/lib/commands/command-plugin-add.bash @@ -1,8 +1,8 @@ # -*- sh -*- plugin_add_command() { - if [[ $# -lt 1 || $# -gt 2 ]]; then - display_error "usage: asdf plugin add []" + if [[ $# -lt 1 || $# -gt 3 ]]; then + display_error "usage: asdf plugin add [] []" exit 1 fi @@ -26,6 +26,8 @@ plugin_add_command() { exit 1 fi + local git_ref="$3" + local plugin_path plugin_path=$(get_plugin_path "$plugin_name") @@ -38,7 +40,13 @@ plugin_add_command() { asdf_run_hook "pre_asdf_plugin_add" "$plugin_name" asdf_run_hook "pre_asdf_plugin_add_${plugin_name}" - if ! git clone -q "$source_url" "$plugin_path"; then + declare -a git_clone_opts + git_clone_opts+=("-q") + if [ -n "$git_ref" ]; then + git_clone_opts+=("-b" "$git_ref") + fi + + if ! git clone "${git_clone_opts[@]}" "$source_url" "$plugin_path"; then exit 1 fi diff --git a/test/plugin_add_command.bats b/test/plugin_add_command.bats index 021e38508..6aa9fc80b 100644 --- a/test/plugin_add_command.bats +++ b/test/plugin_add_command.bats @@ -52,6 +52,16 @@ teardown() { [ "$output" = "dummy" ] } +@test "plugin_add command with URL and git-ref specified adds a plugin at branch" { + install_mock_plugin_repo "dummy" "develop" + + run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy" "develop" + [ "$status" -eq 0 ] + + run asdf plugin-list + [ "$output" = "dummy" ] +} + @test "plugin_add command with URL specified run twice returns error second time" { install_mock_plugin_repo "dummy" diff --git a/test/test_helpers.bash b/test/test_helpers.bash index 1704fce78..913ce5273 100644 --- a/test/test_helpers.bash +++ b/test/test_helpers.bash @@ -45,9 +45,10 @@ install_mock_broken_plugin() { install_mock_plugin_repo() { local plugin_name=$1 + local branch_name="${2:-master}" local location="${BASE_DIR}/repo-${plugin_name}" cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin" "${location}" - git -C "${location}" init -q + git -C "${location}" init -q -b "$branch_name" git -C "${location}" config user.name "Test" git -C "${location}" config user.email "test@example.com" git -C "${location}" add -A