Skip to content

Commit ece60e9

Browse files
authored
fix: version injection
fix: version injection
2 parents 2b05907 + 986cd73 commit ece60e9

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ linters:
2020
- noinlineerr
2121
# Intentionally using time.Local for user's local timezone
2222
- gosmopolitan
23+
# strings.SplitSeq doesn't exist in Go 1.21
24+
- modernize

cmd/gitcommit/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"github.com/sgaunet/gitcommit/internal/cli"
1111
)
1212

13+
// version is set via ldflags during build.
14+
var version = "dev"
15+
1316
func main() {
1417
// Setup structured logging with slog
1518
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
@@ -18,7 +21,7 @@ func main() {
1821
slog.SetDefault(logger)
1922

2023
// Create configuration
21-
config := cli.NewConfig()
24+
config := cli.NewConfig(version)
2225

2326
// Parse command-line flags
2427
flag.BoolVar(&config.ShowHelp, "help", false, "Show help message")
@@ -32,7 +35,7 @@ func main() {
3235

3336
// Handle --version flag
3437
if config.ShowVersion {
35-
fmt.Printf("gitcommit version %s\n", config.Version)
38+
fmt.Printf("%s\n", config.Version)
3639
os.Exit(cli.ExitSuccess)
3740
}
3841

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/sgaunet/gitcommit
22

3-
go 1.25.4
3+
go 1.25

internal/cli/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ type Config struct {
2020
Args []string
2121
}
2222

23-
// NewConfig creates a new Config with default values.
24-
func NewConfig() *Config {
23+
// NewConfig creates a new Config with the specified version.
24+
func NewConfig(version string) *Config {
25+
// If version is empty, use a default
26+
if version == "" {
27+
version = "dev"
28+
}
2529
return &Config{
26-
Version: "1.0.0",
30+
Version: version,
2731
}
2832
}
2933

tests/integration/cli_args_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ func TestVersionFlag(t *testing.T) {
8181
t.Fatalf("Version flag should not error: %v\nOutput: %s", err, output)
8282
}
8383

84-
expected := "gitcommit version 1.0.0"
85-
if !strings.Contains(string(output), expected) {
86-
t.Errorf("Expected output containing %q, got: %s", expected, output)
84+
// Check that version output is not empty
85+
outputStr := strings.TrimSpace(string(output))
86+
if outputStr == "" {
87+
t.Errorf("Expected version output, got empty string")
88+
}
89+
90+
// Version should be "dev" during testing or a semver string when built
91+
if outputStr != "dev" && !strings.Contains(outputStr, ".") {
92+
t.Errorf("Expected valid version output (dev or semver), got: %s", outputStr)
8793
}
8894
})
8995
}

0 commit comments

Comments
 (0)