Skip to content

Commit

Permalink
squash: Exclude plugins with specific versions from updates
Browse files Browse the repository at this point in the history
  • Loading branch information
theoretick committed Aug 21, 2021
1 parent a593511 commit 403c8c9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
19 changes: 14 additions & 5 deletions lib/commands/command-plugin-update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion test/plugin_add_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
15 changes: 15 additions & 0 deletions test/plugin_update_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
3 changes: 2 additions & 1 deletion test/test_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 403c8c9

Please sign in to comment.