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
7 changes: 3 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ The flow is: `pro.go` (CLI wiring) → `command/` (orchestration + user-facing o
- `list.go` — interactive PR/MR picker using `ktr0731/go-fuzzyfinder`.
- `auth.go` — prompts for and saves a personal access token.

- **`repository/`** — wraps `go-git` to find the repo and read the origin URL. Two things are done manually rather than through go-git:
- **Worktree support**: `CurrentBranchName` reads and parses the `.git/HEAD` file directly because go-git does not resolve branches correctly inside external worktrees. `makeRepository` detects the `.git/worktrees` path and tracks both the worktree git dir and the real git dir separately.
- **Parent traversal**: `FindInParents` recurses up the directory tree until it finds a git repo or hits the filesystem root.
- Typed errors live in `errors.go` (`ErrNoRemoteOrigin`, `ErrNoActiveBranch`) and are matched with `errors.Is` in `command/`.
- **`repository/`** — wraps `go-git` to find the repo, read the current branch, and read the origin URL. `FindInParents` opens the repo with `PlainOpenWithOptions{DetectDotGit: true}`, which walks up parent directories itself, so no manual traversal is needed. Linked worktrees need no special handling — go-git resolves both HEAD and the shared config from inside a worktree.
- Typed errors live in `errors.go` (`ErrNoRepository`, `ErrNoRemoteOrigin`, `ErrNoActiveBranch`) and are matched with `errors.Is` in `command/`. A detached HEAD or a branch without commits yields `ErrNoActiveBranch`.
- **go-git is pinned to a v6 alpha on purpose.** v5 cannot open any repository whose config sets the `worktreeConfig` extension (git enables it automatically for per-worktree config): v5's `extensionsValidForV0` allow-list keys are camelCase while lookups are lowercased, so `worktreeconfig` misses and `Open` rejects the repo. v5.19.1 is the last v5, and `verifyExtensions` is unconditional, so v6 is the only fix. Don't downgrade to v5.

- **`provider/github/` and `provider/gitlab/`** — one file each, self-contained REST clients built on `net/http` (no SDK). Each finds the PR/MR for a branch and lists remote branches, handles pagination, and returns typed sentinel errors (e.g. `ErrNotFound`/`ErrUnauthorized`, `ErrMergeRequestNotFound`/`ErrProjectNotFound`/`ErrTokenExpired`). The two providers do not share an interface — `command/` switches on host and calls each directly.

Expand Down
10 changes: 7 additions & 3 deletions command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import (
func List(repoPath string, print bool, copy bool) {
repo, err := repository.FindInParents(repoPath)
if err != nil {
fmt.Fprintln(os.Stderr, color.RedString("Unable to find git repository in given directory or any of parent directories."))
fmt.Fprintln(os.Stderr, "Please make sure you are in the project directory.")
if errors.Is(err, repository.ErrNoRepository) {
fmt.Fprintln(os.Stderr, color.RedString("Unable to find git repository in given directory or any of parent directories."))
fmt.Fprintln(os.Stderr, "Please make sure you are in the project directory.")
} else {
fmt.Fprintln(os.Stderr, color.RedString("Unable to open git repository: %s", err.Error()))
}
os.Exit(1)
}

Expand All @@ -28,10 +32,10 @@ func List(repoPath string, print bool, copy bool) {
if errors.Is(err, repository.ErrNoRemoteOrigin) {
fmt.Fprintln(os.Stderr, color.RedString("No remote named \"origin\" found."))
fmt.Fprintln(os.Stderr, "Please make sure you have a remote named \"origin\".")
os.Exit(1)
} else {
fmt.Fprintln(os.Stderr, color.RedString("Unable to get origin URL: %s", err.Error()))
}
os.Exit(1)
}

gitURL, err := giturl.Parse(originURL)
Expand Down
10 changes: 7 additions & 3 deletions command/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import (
func Open(repoPath string, print bool, copy bool) {
repo, err := repository.FindInParents(repoPath)
if err != nil {
fmt.Fprintln(os.Stderr, color.RedString("Unable to find git repository in given directory or any of parent directories."))
fmt.Fprintln(os.Stderr, "Please make sure you are in the project directory.")
if errors.Is(err, repository.ErrNoRepository) {
fmt.Fprintln(os.Stderr, color.RedString("Unable to find git repository in given directory or any of parent directories."))
fmt.Fprintln(os.Stderr, "Please make sure you are in the project directory.")
} else {
fmt.Fprintln(os.Stderr, color.RedString("Unable to open git repository: %s", err.Error()))
}
os.Exit(1)
}

Expand All @@ -31,10 +35,10 @@ func Open(repoPath string, print bool, copy bool) {
if errors.Is(err, repository.ErrNoRemoteOrigin) {
fmt.Fprintln(os.Stderr, color.RedString("No remote named \"origin\" found."))
fmt.Fprintln(os.Stderr, "Please make sure you have a remote named \"origin\".")
os.Exit(1)
} else {
fmt.Fprintln(os.Stderr, color.RedString("Unable to get origin URL: %s", err.Error()))
}
os.Exit(1)
}

gitURL, err := giturl.Parse(originURL)
Expand Down
17 changes: 7 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ go 1.26.4
require (
github.com/atotto/clipboard v0.1.4
github.com/fatih/color v1.19.0
github.com/go-git/go-billy/v5 v5.9.0
github.com/go-git/go-git/v5 v5.19.1
github.com/go-git/go-git/v6 v6.0.0-alpha.4
github.com/ktr0731/go-fuzzyfinder v0.9.0
github.com/mitchellh/go-homedir v1.1.0
github.com/urfave/cli/v2 v2.27.7
Expand All @@ -15,21 +14,19 @@ require (
)

require (
dario.cat/mergo v1.0.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.4.1 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/gdamore/tcell/v2 v2.13.10 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/go-git/gcfg/v2 v2.0.2 // indirect
github.com/go-git/go-billy/v6 v6.0.0-alpha.1 // indirect
github.com/kevinburke/ssh_config v1.6.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/ktr0731/go-ansisgr v0.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.15 // indirect
Expand All @@ -39,14 +36,14 @@ require (
github.com/pjbgf/sha1cd v0.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.37.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading
Loading