Skip to content

Commit 592758a

Browse files
committed
Fix g not activating selected version when system one is available
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.
1 parent b652453 commit 592758a

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

89
## 0.9.1 - 2022-10-23
910

bin/g

+15-17
Original file line numberDiff line numberDiff line change
@@ -588,24 +588,22 @@ set_version() {
588588
error_and_abort "Version $version is not available. Use 'g install $version' to install it."
589589
fi
590590

591-
if [ "$version" != "$active" ]; then
592-
if [ ! -e "$dir/g.lock" ]; then
593-
for file in "$dir/"*; do
594-
if [ -L "${GOROOT:?}/$(basename "$file")" ]; then
595-
rm "${GOROOT:?}/$(basename "$file")"
596-
elif [ -e "${GOROOT:?}/$(basename "$file")" ]; then
597-
# enable seamless upgrade to symlink behavior
598-
rm -rf "${GOROOT:?}/$(basename "$file")"
599-
fi
600-
ln -sf "$file" "${GOROOT:?}/$(basename "$file")"
601-
done
591+
if [ ! -e "$dir/g.lock" ]; then
592+
for file in "$dir/"*; do
593+
if [ -L "${GOROOT:?}/$(basename "$file")" ]; then
594+
rm "${GOROOT:?}/$(basename "$file")"
595+
elif [ -e "${GOROOT:?}/$(basename "$file")" ]; then
596+
# enable seamless upgrade to symlink behavior
597+
rm -rf "${GOROOT:?}/$(basename "$file")"
598+
fi
599+
ln -sf "$file" "${GOROOT:?}/$(basename "$file")"
600+
done
602601

603-
for file in "$dir/bin/"*; do
604-
ln -sf "$GOROOT/bin/$(basename "$file")" "$GOPATH/bin/"
605-
done
606-
else
607-
error_and_abort "version $version installation might be corrupted"
608-
fi
602+
for file in "$dir/bin/"*; do
603+
ln -sf "$GOROOT/bin/$(basename "$file")" "$GOPATH/bin/"
604+
done
605+
else
606+
error_and_abort "version $version installation might be corrupted"
609607
fi
610608
}
611609

0 commit comments

Comments
 (0)