| 1 |
Description: Allow setting the version via ldflags |
| 2 |
Upstream commit 1409e2c (cmd/shfmt: drop support for setting the version |
| 3 |
via ldflags) dropped support for setting the version via ldflags. The version |
| 4 |
is now stamped in the binary by go-build(1) based on the tag and/or the commit |
| 5 |
hash. |
| 6 |
|
| 7 |
Since this upstream change breaks `shfmt --version`, let's revert the |
| 8 |
aforementioned commit. |
| 9 |
Author: Vincent Blut <[email protected]> |
| 10 |
Forwarded: no |
| 11 |
Last-Update: 2026-05-14 |
| 12 |
--- |
| 13 |
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ |
| 14 |
--- a/cmd/shfmt/main.go |
| 15 |
+++ b/cmd/shfmt/main.go |
| 16 |
@@ -105,6 +105,8 @@ |
| 17 |
color bool |
| 18 |
|
| 19 |
copyBuf = make([]byte, 32*1024) |
| 20 |
+ |
| 21 |
+ version = "(devel)" |
| 22 |
) |
| 23 |
|
| 24 |
func main() { |
| 25 |
@@ -156,8 +158,7 @@ |
| 26 |
flag.Parse() |
| 27 |
|
| 28 |
if versionFlag.val { |
| 29 |
- version := "(unknown)" |
| 30 |
- if info, ok := debug.ReadBuildInfo(); ok { |
| 31 |
+ if info, ok := debug.ReadBuildInfo(); ok && version == "(devel)" { |
| 32 |
mod := &info.Main |
| 33 |
if mod.Replace != nil { |
| 34 |
mod = mod.Replace |