Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4155d78440 | |||
| 6e21a0798a | |||
| d00ffdb37c |
27
Makefile
Normal file
27
Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
.PHONY: build install test coverage clean
|
||||
|
||||
# Build the binary (Go automatically embeds VCS info)
|
||||
build:
|
||||
@echo "Building gitlocal..."
|
||||
go build -o gitlocal .
|
||||
|
||||
# Install to $GOPATH/bin
|
||||
install:
|
||||
@echo "Installing gitlocal..."
|
||||
go install .
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
go test -v ./...
|
||||
|
||||
# Run tests with coverage
|
||||
coverage:
|
||||
@echo "Running tests with coverage..."
|
||||
go test -coverprofile=coverage.out ./...
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
rm -f gitlocal coverage.out
|
||||
35
README.md
35
README.md
@@ -74,6 +74,19 @@ Converted Repositories (2):
|
||||
Branch: master
|
||||
```
|
||||
|
||||
### Show version information
|
||||
|
||||
```bash
|
||||
gitlocal version
|
||||
```
|
||||
|
||||
Example output:
|
||||
```
|
||||
gitlocal version v0.1.0
|
||||
Commit: a1b2c3d
|
||||
Built: 2026-04-11T14:30:00Z
|
||||
```
|
||||
|
||||
## Using git with .gitlocal
|
||||
|
||||
Add this alias to your `.zshrc` or `.bashrc`:
|
||||
@@ -122,12 +135,32 @@ cd gitlocal
|
||||
go mod download
|
||||
|
||||
# Build the binary
|
||||
make build
|
||||
# or
|
||||
go build -o gitlocal
|
||||
|
||||
# Or install directly to $GOPATH/bin
|
||||
# Install to $GOPATH/bin
|
||||
make install
|
||||
# or
|
||||
go install
|
||||
```
|
||||
|
||||
**Version Information:**
|
||||
Go automatically embeds version information from git when building. The `gitlocal version` command reads this embedded metadata to display:
|
||||
- Version (from git tag, e.g., `v0.1.0`)
|
||||
- Commit hash (short SHA)
|
||||
- Build timestamp
|
||||
|
||||
This works automatically for:
|
||||
- `go install` (remote installation)
|
||||
- `go build` (local builds)
|
||||
- Pre-built binaries (when built from a git repo)
|
||||
|
||||
Check the version after installing:
|
||||
```bash
|
||||
gitlocal version
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
|
||||
46
cmd/version.go
Normal file
46
cmd/version.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Long: `Display the version, commit hash, and build date of gitlocal.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
version := "dev"
|
||||
commit := "unknown"
|
||||
date := "unknown"
|
||||
|
||||
// Read version from build info (works for both 'go install' and 'go build')
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
version = info.Main.Version
|
||||
|
||||
// Extract commit and date from build settings
|
||||
for _, setting := range info.Settings {
|
||||
switch setting.Key {
|
||||
case "vcs.revision":
|
||||
if len(setting.Value) > 7 {
|
||||
commit = setting.Value[:7]
|
||||
} else {
|
||||
commit = setting.Value
|
||||
}
|
||||
case "vcs.time":
|
||||
date = setting.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("gitlocal version %s\n", version)
|
||||
fmt.Printf(" Commit: %s\n", commit)
|
||||
fmt.Printf(" Built: %s\n", date)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user