From 403c8c9cdd1d364a906f447ce5cd42e81e412a0e Mon Sep 17 00:00:00 2001 From: Lucas Charles Date: Sun, 8 Aug 2021 14:40:18 -0700 Subject: [PATCH] squash: Exclude plugins with specific versions from updates --- lib/commands/command-plugin-update.bash | 19 ++++++++++++++----- test/plugin_add_command.bats | 2 +- test/plugin_update_command.bats | 15 +++++++++++++++ test/test_helpers.bash | 3 ++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/commands/command-plugin-update.bash b/lib/commands/command-plugin-update.bash index 1e6f531f7..1d96763a1 100644 --- a/lib/commands/command-plugin-update.bash +++ b/lib/commands/command-plugin-update.bash @@ -30,11 +30,20 @@ update_plugin() { plugin_remote_default_branch=$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" ls-remote --symref origin HEAD | awk '{ sub(/refs\/heads\//, ""); print $2; exit }') local gitref=${3:-${plugin_remote_default_branch}} logfile=$(mktemp) - { - printf "Updating %s to %s\\n" "$plugin_name" "$gitref" - git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" fetch --prune --update-head-ok origin "$gitref:$gitref" - git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" -c advice.detachedHead=false checkout --force "$gitref" - } >"$logfile" 2>&1 + + local current_ref="$(git --git-dir "$plugin_path/.git" rev-parse --abbrev-ref --symbolic-full-name HEAD)" + if [ "$current_ref" = "HEAD" ]; then + { + printf "Skipping detached %s\\n" "$plugin_name" + } >"$logfile" 2>&1 + else + { + printf "Updating %s to %s\\n" "$plugin_name" "$gitref" + git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" fetch --prune --update-head-ok origin "$gitref:$gitref" + git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" -c advice.detachedHead=false checkout --force "$gitref" + } >"$logfile" 2>&1 + fi + cat "$logfile" rm "$logfile" } diff --git a/test/plugin_add_command.bats b/test/plugin_add_command.bats index 05b1539af..8e38b7f1e 100644 --- a/test/plugin_add_command.bats +++ b/test/plugin_add_command.bats @@ -53,7 +53,7 @@ teardown() { } @test "plugin_add command with URL and git-ref specified adds a plugin using repo" { - install_mock_plugin_repo_with_ref "dummy" + install_mock_plugin_repo_with_ref "dummy" "tagname" run asdf plugin-add "dummy" "${BASE_DIR}/repo-dummy" "tagname" [ "$status" -eq 0 ] diff --git a/test/plugin_update_command.bats b/test/plugin_update_command.bats index 494bda44f..88f642a37 100644 --- a/test/plugin_update_command.bats +++ b/test/plugin_update_command.bats @@ -80,6 +80,21 @@ teardown() { [ "$repo_head" = "main" ] } +@test "asdf plugin-update should skip updates for detached plugin" { + install_mock_plugin_repo_with_ref "dummy" "tagname" + + run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy" "tagname" + [ "$status" -eq 0 ] + + run asdf plugin update dummy-tagname + + current_ref="$(git --git-dir "$ASDF_DIR/plugins/dummy-tagname/.git" --work-tree "$ASDF_DIR/plugins/dummy-tagname" describe --tags)" + + [ "$status" -eq 0 ] + [[ "$output" =~ "Skipping dummy-tagname"* ]] + [ "$current_ref" = "tagname" ] +} + @test "asdf plugin-update should not remove plugin versions" { run asdf install dummy 1.1 [ "$status" -eq 0 ] diff --git a/test/test_helpers.bash b/test/test_helpers.bash index d6ade7fbb..eb02c7cc8 100644 --- a/test/test_helpers.bash +++ b/test/test_helpers.bash @@ -57,8 +57,9 @@ install_mock_plugin_repo() { install_mock_plugin_repo_with_ref() { install_mock_plugin_repo "$1" local plugin_name=$1 + local tagname=$2 local location="${BASE_DIR}/repo-${plugin_name}" - git -C "${location}" tag "tagname" + git -C "${location}" tag "${tagname}" } install_mock_plugin_version() {