Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
push:
branches:
- main
- codex/**
pull_request:

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Go Vet
run: go vet ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Release
on:
push:
tags: [ "v*.*.*" ]
tags-ignore: [ "*-*" ]

permissions:
contents: write

jobs:
release:
Expand All @@ -15,7 +19,7 @@ jobs:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
version: "~> v2"
args: release --clean --timeout 60m
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 7 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
builds:
- main: ./main.go
id: fastcommit
binary: fastcommit
id: fastgit
binary: fastgit
skip: false
env:
- CGO_ENABLED=0
- GOPROXY=https://goproxy.io
- GOPROXY=https://proxy.golang.org,direct
- GOSUMDB=sum.golang.org
targets:
- "darwin_amd64"
- "darwin_arm64"
Expand All @@ -14,7 +15,7 @@ builds:
- "linux_arm64"
ldflags:
- -X 'github.com/pubgo/funk/v2/buildinfo.version=v{{ .Version }}'
- -X 'github.com/pubgo/funk/v2/buildinfo.project=fastcommit'
- -X 'github.com/pubgo/funk/v2/buildinfo.project=fastgit'
- -X 'github.com/pubgo/funk/v2/buildinfo.buildTime={{ .CommitDate }}'
- -X 'github.com/pubgo/funk/v2/buildinfo.commitID={{ .ShortCommit }}'
flags:
Expand Down Expand Up @@ -65,8 +66,8 @@ changelog:
release:
github:
owner: pubgo
name: fastcommit
name: fastgit
name_template: '{{ .ProjectName }} {{ .Tag }}'
footer: |
## Installation
Download the latest release from the [GitHub Releases](https://github.com/pubgo/fastcommit/releases) page.
Download the latest release from the [GitHub Releases](https://github.com/pubgo/fastgit/releases) page.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ agentic git commit generate tool
- `fastgit docs init`: 初始化文档维护用的 prompt / instruction 模板
- `fastgit pull`: 拉取当前分支(支持 `--all`)
- `fastgit push`: 推送当前分支(支持 `--all` / `--force`)
- `fastgit worktree`: 列出当前仓库 worktree
- `fastgit worktree create <issue|branch> [--base <branch>]`: 创建 worktree
- `fastgit worktree remove <issue|branch>`: 删除 worktree
- `fastgit worktree remove --path <worktree-path>`: 按路径删除 worktree
- `fastgit ggc list`: 查看统一命令面(ggc 风格)
- `fastgit ggc <command ...>`: 执行统一命令,例如 `fastgit ggc status short`
- `fastgit ggc` / `fastgit ggc interactive`: 进入交互模式(增量搜索 + workflow)
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ tasks:

vet:
cmds:
- go vet ./...
- env -u GOROOT go vet ./...
test:
cmds:
- go test -short -race -v ./... -cover
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pubgo/fastgit/cmds/tagcmd"
"github.com/pubgo/fastgit/cmds/upgradecmd"
"github.com/pubgo/fastgit/cmds/versioncmd"
"github.com/pubgo/fastgit/cmds/worktreecmd"
"github.com/pubgo/fastgit/utils"
"github.com/pubgo/funk/v2/assert"
"github.com/pubgo/funk/v2/config"
Expand All @@ -48,6 +49,7 @@ func Main() {
docscmd.New(),
pullcmd.New(),
pushcmd.New(),
worktreecmd.New(),
chglogcmd.NewCommand(),
copilotcmd.New(),
)
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func initConfig() {
type versionConfigProvider struct {
Version *configs.Version `yaml:"version"`
}
var cfg versionConfigProvider
config.LoadFromPath(&cfg, configPath)
cfgResult := assert.Must1(config.LoadFromPath[versionConfigProvider](configPath))
cfg := cfgResult.T

var defaultCfg versionConfigProvider
defaultConfigData := configs.GetDefaultConfig()
Expand Down
7 changes: 2 additions & 5 deletions cmds/spin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import (
)

func main() {
for {
color.Output.Write([]byte("\rhello world"))
time.Sleep(time.Second)
}
return
color.Output.Write([]byte("\rhello world"))
time.Sleep(time.Second)
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
s.Color("red") // Set the spinner color to red
s.Start() // Start the spinner
Expand Down
1 change: 0 additions & 1 deletion cmds/testcmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func main() {
time.Sleep(time.Minute)
spin.Stop("Connected", 0)
fmt.Println()
return
fmt.Println("Styled Select Example")
fmt.Println("Use arrow keys (or hjkl) to navigate, Enter to select, Ctrl+C to cancel")
fmt.Println()
Expand Down
136 changes: 136 additions & 0 deletions cmds/worktreecmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package worktreecmd

import (
"context"
"fmt"
"strings"

"github.com/pubgo/fastgit/utils"
"github.com/pubgo/redant"
)

func New() *redant.Command {
var createFlags = struct {
base string
}{
base: "main",
}

var removeFlags = struct {
path bool
}{}

listHandler := func(ctx context.Context, i *redant.Invocation) error {
worktrees, err := utils.ListWorktrees()
if err != nil {
return err
}

fmt.Printf("%-1s %-20s %-10s %s\n", " ", "BRANCH", "COMMIT", "PATH")
for _, wt := range worktrees {
marker := " "
if wt.IsCurrent {
marker = "*"
}

branch := wt.Branch
if wt.IsDetached || branch == "" {
branch = "(detached)"
}

commit := wt.Commit
if len(commit) > 8 {
commit = commit[:8]
}

fmt.Printf("%-1s %-20s %-10s %s\n", marker, branch, commit, wt.Path)
}
return nil
}

return &redant.Command{
Use: "worktree",
Short: "Manage git worktrees",
Children: []*redant.Command{
{
Use: "list",
Short: "List all worktrees",
Handler: func(ctx context.Context, i *redant.Invocation) error {
if len(i.Command.Args) > 0 {
return redant.DefaultHelpFn()(ctx, i)
}
return listHandler(ctx, i)
},
},
{
Use: "create",
Short: "Create a worktree from an issue id/branch",
Options: []redant.Option{
{
Flag: "base",
Description: "Base branch to create from",
Value: redant.StringOf(&createFlags.base),
Default: "main",
},
},
Handler: func(ctx context.Context, i *redant.Invocation) error {
args := commandArgs(i)
if len(args) != 1 {
return redant.DefaultHelpFn()(ctx, i)
}

path, err := utils.CreateWorktree(args[0], createFlags.base)
if err != nil {
return err
}

fmt.Printf("created worktree: %s\n", path)
return nil
},
},
{
Use: "remove",
Short: "Remove a worktree by issue id/branch or by path",
Options: []redant.Option{
{
Flag: "path",
Description: "Treat argument as an absolute/relative worktree path",
Value: redant.BoolOf(&removeFlags.path),
},
},
Handler: func(ctx context.Context, i *redant.Invocation) error {
args := commandArgs(i)
if len(args) != 1 {
return redant.DefaultHelpFn()(ctx, i)
}

var err error
if removeFlags.path {
err = utils.RemoveWorktreeByPath(args[0])
} else {
err = utils.RemoveWorktree(args[0])
}

if err != nil {
return err
}

fmt.Printf("removed worktree: %s\n", args[0])
return nil
},
},
},
Handler: listHandler,
}
}

func commandArgs(i *redant.Invocation) []string {
args := make([]string, 0, len(i.Command.Args))
for _, arg := range i.Command.Args {
value := strings.TrimSpace(arg.Value.String())
if value != "" {
args = append(args, value)
}
}
return args
}
Loading
Loading