Skip to content

Commit 343418e

Browse files
committed
Initial go port of git-wt script
0 parents  commit 343418e

29 files changed

Lines changed: 2778 additions & 0 deletions

.git-wt.yaml.example

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Example git-wt configuration file
2+
# Copy this to .git-wt.yaml in your repository root and customize
3+
4+
setup:
5+
# Node.js project example
6+
- name: npm-install
7+
description: Install npm dependencies
8+
script: npm install
9+
10+
# Copy environment file
11+
- name: copy-env
12+
description: Copy environment configuration
13+
script: |
14+
if [ -f $GIT_ROOT/.env ]; then
15+
cp $GIT_ROOT/.env $WORKTREE_PATH/.env
16+
echo "Environment file copied"
17+
fi
18+
19+
# Database setup
20+
- name: db-migrate
21+
description: Run database migrations
22+
script: npm run db:migrate
23+
24+
# Python project example
25+
# - name: pip-install
26+
# description: Install Python dependencies
27+
# script: pip install -r requirements.txt
28+
29+
# Go project example
30+
# - name: go-deps
31+
# description: Download Go dependencies
32+
# script: go mod download
33+
34+
# Ruby project example
35+
# - name: bundle-install
36+
# description: Install Ruby gems
37+
# script: bundle install
38+
39+
# Custom build step
40+
# - name: build
41+
# description: Build the project
42+
# script: npm run build
43+
44+
teardown:
45+
# Clean up build artifacts
46+
- name: clean-build
47+
description: Remove build artifacts
48+
script: rm -rf dist/ build/
49+
50+
# Clean up cache
51+
- name: clean-cache
52+
description: Remove cache files
53+
script: |
54+
rm -rf node_modules/.cache
55+
rm -rf .cache
56+
57+
# Database cleanup (optional)
58+
# - name: db-cleanup
59+
# description: Clean up test data
60+
# script: npm run db:clean
61+
62+
# Environment variables available in scripts:
63+
# - GIT_ROOT: Repository root path
64+
# - WORKTREE_PATH: Full path to the worktree
65+
# - WORKTREE_NAME: Branch name
66+
# - BASE_BRANCH: Parent branch

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.21'
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v5
27+
with:
28+
distribution: goreleaser
29+
version: latest
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
go: ['1.21', '1.22']
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ matrix.go }}
25+
26+
- name: Build
27+
run: go build -v .
28+
29+
- name: Test
30+
run: go test -v ./...
31+
32+
- name: Vet
33+
run: go vet ./...

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Binaries
2+
git-wt
3+
*.exe
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Build artifacts
15+
dist/
16+
bin/
17+
18+
# Dependency directories
19+
vendor/
20+
21+
# Go workspace file
22+
go.work
23+
24+
# IDE specific files
25+
.idea/
26+
.vscode/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS specific files
32+
.DS_Store
33+
Thumbs.db
34+
dist/

.goreleaser.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
project_name: git-wt
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
- go fmt ./...
7+
8+
builds:
9+
- id: git-wt
10+
binary: git-wt
11+
env:
12+
- CGO_ENABLED=0
13+
goos:
14+
- linux
15+
- darwin
16+
- windows
17+
goarch:
18+
- amd64
19+
- arm64
20+
ldflags:
21+
- -s -w
22+
- -X main.version={{.Version}}
23+
- -X main.commit={{.Commit}}
24+
- -X main.date={{.Date}}
25+
26+
archives:
27+
- id: git-wt
28+
format: tar.gz
29+
format_overrides:
30+
- goos: windows
31+
format: zip
32+
name_template: >-
33+
{{ .ProjectName }}_
34+
{{- .Version }}_
35+
{{- title .Os }}_
36+
{{- if eq .Arch "amd64" }}x86_64
37+
{{- else if eq .Arch "386" }}i386
38+
{{- else }}{{ .Arch }}{{ end }}
39+
files:
40+
- README.md
41+
- LICENSE
42+
43+
checksum:
44+
name_template: 'checksums.txt'
45+
46+
snapshot:
47+
name_template: "{{ incpatch .Version }}-next"
48+
49+
changelog:
50+
sort: asc
51+
filters:
52+
exclude:
53+
- '^docs:'
54+
- '^test:'
55+
- '^ci:'
56+
57+
brews:
58+
- name: git-wt
59+
repository:
60+
owner: shogs
61+
name: homebrew-tap
62+
homepage: https://github.com/shogs/git-wt
63+
description: Git worktree management tool
64+
install: |
65+
bin.install "git-wt"
66+
test: |
67+
system "#{bin}/git-wt", "--version"

CHANGELOG.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2024-10-28
9+
10+
### Added
11+
- Initial release of git-wt Go CLI
12+
- Port of bash script functionality to Go
13+
- Commands:
14+
- `init` - Initialize git-wt configuration
15+
- `new`/`add` - Create new worktree
16+
- `switch` - Switch to a worktree
17+
- `resume` - Resume work with session info
18+
- `remove` - Remove a worktree
19+
- `list` - List all worktrees
20+
- `status` - Show repository status
21+
- `clean` - Interactive cleanup of merged branches
22+
- `task` - Create worktree with task description
23+
- `root`/`main` - Return to repository root
24+
- YAML configuration support without external dependencies
25+
- Auto-detection of project types (Node.js, Python, Go, Ruby)
26+
- Session tracking with task descriptions
27+
- Setup and teardown action support
28+
- Cross-platform builds (macOS, Linux, Windows)
29+
- Installation script
30+
- GoReleaser configuration
31+
- GitHub Actions workflows
32+
- Comprehensive documentation
33+
34+
### Changed
35+
- No longer depends on `yq` for YAML parsing
36+
- Improved error handling and validation
37+
- Better cross-platform compatibility
38+
39+
### Security
40+
- Prevents removal of worktree while inside it
41+
- Checks for uncommitted changes before removal
42+
- Safe handling of file operations
43+
44+
## [Unreleased]
45+
46+
### Planned
47+
- Template support for common project types
48+
- Git hooks integration
49+
- Worktree archiving
50+
- Batch operations
51+
- Custom worktree locations
52+
- Plugin system

0 commit comments

Comments
 (0)