| 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 |
Index: golang-mvdan-sh/cmd/shfmt/main.go |
| 15 |
=================================================================== |
| 16 |
--- golang-mvdan-sh.orig/cmd/shfmt/main.go |
| 17 |
+++ golang-mvdan-sh/cmd/shfmt/main.go |
| 18 |
@@ -103,6 +103,8 @@ var ( |
| 19 |
color bool |
| 20 |
|
| 21 |
copyBuf = make([]byte, 32*1024) |
| 22 |
+ |
| 23 |
+ version = "(devel)" |
| 24 |
) |
| 25 |
|
| 26 |
func main() { |
| 27 |
@@ -153,8 +155,7 @@ For more information and to report bugs, |
| 28 |
flag.Parse() |
| 29 |
|
| 30 |
if versionFlag.val { |
| 31 |
- version := "(unknown)" |
| 32 |
- if info, ok := debug.ReadBuildInfo(); ok { |
| 33 |
+ if info, ok := debug.ReadBuildInfo(); ok && version == "(devel)" { |
| 34 |
mod := &info.Main |
| 35 |
if mod.Replace != nil { |
| 36 |
mod = mod.Replace |