Merge pull request #250 from Jwashton/duplicate-shims

Duplicate shims
This commit is contained in:
vic 2017-10-27 11:50:11 -05:00 committed by GitHub
commit 85bebfaf0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View File

@ -58,7 +58,8 @@ write_shim_script() {
cp "$plugin_shims_path/$executable_name" "$shim_path" cp "$plugin_shims_path/$executable_name" "$shim_path"
elif [ -f "$shim_path" ]; then elif [ -f "$shim_path" ]; then
if ! grep "# asdf-plugin-version: $version" "$shim_path" > /dev/null; then if ! grep "# asdf-plugin-version: $version" "$shim_path" > /dev/null; then
sed -i'' -e "s/\(asdf-plugin: $plugin_name\)/\1\\"$'\n'"# asdf-plugin-version: $version/" "$shim_path" sed -i.bak -e "s/\(asdf-plugin: $plugin_name\)/\1\\"$'\n'"# asdf-plugin-version: $version/" "$shim_path"
rm "$shim_path".bak
fi fi
else else
cat <<EOF > "$shim_path" cat <<EOF > "$shim_path"
@ -210,7 +211,8 @@ remove_shim_for_version() {
return 0 return 0
fi fi
sed -i'' -e "/# asdf-plugin-version: $version/d" "$shim_path" sed -i.bak -e "/# asdf-plugin-version: $version/d" "$shim_path"
rm "$shim_path".bak
if [ ! -f "$plugin_shims_path/$executable_name" ] && \ if [ ! -f "$plugin_shims_path/$executable_name" ] && \
! grep "# asdf-plugin-version" "$shim_path" > /dev/null || \ ! grep "# asdf-plugin-version" "$shim_path" > /dev/null || \

View File

@ -25,7 +25,8 @@ version_command() {
done done
if [ -f "$file" ] && grep "$plugin" "$file" > /dev/null; then if [ -f "$file" ] && grep "$plugin" "$file" > /dev/null; then
sed -i -e "s/$plugin .*/$plugin ${versions[*]}/" "$file" sed -i.bak -e "s/$plugin .*/$plugin ${versions[*]}/" "$file"
rm "$file".bak
else else
echo "$plugin ${versions[*]}" >> "$file" echo "$plugin ${versions[*]}" >> "$file"
fi fi

View File

@ -46,3 +46,24 @@ teardown() {
run grep "asdf-plugin-version: 1.1" "$ASDF_DIR/shims/dummy" run grep "asdf-plugin-version: 1.1" "$ASDF_DIR/shims/dummy"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "reshim should not duplicate shims" {
cd $PROJECT_DIR
run install_command dummy 1.0
run install_command dummy 1.1
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
run rm $ASDF_DIR/shims/*
[ "$status" -eq 0 ]
[ "0" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ]
run reshim_command dummy
[ "$status" -eq 0 ]
[ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ]
run reshim_command dummy
[ "$status" -eq 0 ]
[ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ]
}

View File

@ -63,6 +63,14 @@ teardown() {
[ "$tool_version_contents" = "dummy 1.1.0" ] [ "$tool_version_contents" = "dummy 1.1.0" ]
} }
@test "local should not create a duplicate .tool-versions file if such file exists" {
echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions
run local_command "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(ls $PROJECT_DIR/.tool-versions* | wc -l)" -eq 1 ]
}
@test "local should overwrite the existing version if it's set" { @test "local should overwrite the existing version if it's set" {
echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions
run local_command "dummy" "1.1.0" run local_command "dummy" "1.1.0"