Skip to content

Commit 3f9da19

Browse files
committed
fix(module): Handle X.Y.Z version format
Starting Go 1.21, the 'go' directive in go.mod files takes the form: go X.Y.Z (https://go.dev/doc/go1.21) Given a go.mod file with such a directive, `gimme module` fails because it turns "1.21.5" into "1.21.5.x". This commit fixes the issue by adding the ".x" suffix only if the version is in the form "X.Y". As an added bonus, this will also work for pre-releases: go 1.22rc2
1 parent b4585b0 commit 3f9da19

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gimme

+9-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,15 @@ _get_module() {
701701
die 'not a module'
702702
fi
703703
local version
704-
version="$(awk '$1 == "go" { print $2 ".x"; exit }' "${GIMME_MODULE_PREFIX}go.mod")"
704+
version="$(awk '$1 == "go" {
705+
# Add ".x" suffix if only one ".".
706+
if ($2 ~ /^[0-9]+\.[0-9]+$/) {
707+
print $2 ".x";
708+
} else {
709+
print $2;
710+
}
711+
exit;
712+
}' "${GIMME_MODULE_PREFIX}go.mod")"
705713
if [ -z "$version" ]; then
706714
die 'module has no go directive'
707715
fi

0 commit comments

Comments
 (0)