Skip to content

Commit

Permalink
Fix g not activating selected version when system one is available
Browse files Browse the repository at this point in the history
activate_version would check for the output of `go version` to be
different from the selected one before proceeding. This would be
a nice little performance boost in for such usecase, but relying
on such check makes it prone to errors during g-install process.

This was discovered while running tests in newer versions of
Github Actions on which it had the latest version of go
pre-installed.
  • Loading branch information
stefanmaric committed Jul 10, 2023
1 parent b652453 commit 592758a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add description and website to help command
- Fix Github Actions tests workflow on newer versions of Ubuntu
- Fix g not activating selected version when system one is available

## 0.9.1 - 2022-10-23

Expand Down
32 changes: 15 additions & 17 deletions bin/g
Original file line number Diff line number Diff line change
Expand Up @@ -588,24 +588,22 @@ set_version() {
error_and_abort "Version $version is not available. Use 'g install $version' to install it."
fi

if [ "$version" != "$active" ]; then
if [ ! -e "$dir/g.lock" ]; then
for file in "$dir/"*; do
if [ -L "${GOROOT:?}/$(basename "$file")" ]; then
rm "${GOROOT:?}/$(basename "$file")"
elif [ -e "${GOROOT:?}/$(basename "$file")" ]; then
# enable seamless upgrade to symlink behavior
rm -rf "${GOROOT:?}/$(basename "$file")"
fi
ln -sf "$file" "${GOROOT:?}/$(basename "$file")"
done
if [ ! -e "$dir/g.lock" ]; then
for file in "$dir/"*; do
if [ -L "${GOROOT:?}/$(basename "$file")" ]; then
rm "${GOROOT:?}/$(basename "$file")"
elif [ -e "${GOROOT:?}/$(basename "$file")" ]; then
# enable seamless upgrade to symlink behavior
rm -rf "${GOROOT:?}/$(basename "$file")"
fi
ln -sf "$file" "${GOROOT:?}/$(basename "$file")"
done

for file in "$dir/bin/"*; do
ln -sf "$GOROOT/bin/$(basename "$file")" "$GOPATH/bin/"
done
else
error_and_abort "version $version installation might be corrupted"
fi
for file in "$dir/bin/"*; do
ln -sf "$GOROOT/bin/$(basename "$file")" "$GOPATH/bin/"
done
else
error_and_abort "version $version installation might be corrupted"
fi
}

Expand Down

0 comments on commit 592758a

Please sign in to comment.