gitremote

package
v0.188.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitremote answers "where does this repository live on the web, and which pull requests did a session open", from the machine alone.

Owner request (2026-10-04): from a session, one click to the repository it works in and to the pull requests it opened. Rule 4 holds: nothing here makes a network call. The repository comes from `git remote get-url` in the session's directory, turned into a web address by string rules; the pull requests come from what Claude Code already recorded in its own tool output. A remote this package cannot read as a web host yields no link rather than a guessed one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchURL

func BranchURL(repoURL, branch, defaultBranch string) string

BranchURL is the web page of a branch, or "" when the branch is the default (the repository page already shows it), unknown, or the host's scheme for branch pages is not one this package knows. Hosts are recognised by name, so GitHub Enterprise and self-hosted GitLab are covered when their host says so.

func PushFromOutput added in v0.181.0

func PushFromOutput(out string) (string, bool)

PushFromOutput reads the branch a `git push` sent from what git printed: after the `To <remote>` line, one line per ref, `<flag> <summary> <local> -> <remote ref>`. The first branch that went (a fast-forward, a new branch, a forced update) is the one returned; a rejected ref (`!`), a deleted one (`-`) and a tag are not pushes of a branch. Without a `To` line nothing was pushed — `Everything up-to-date`, or an error.

func PushFromToolPost added in v0.179.1

func PushFromToolPost(payload []byte) (branch string, ok bool)

PushFromToolPost reads the branch a Bash tool's PostToolUse payload pushed. Claude Code records `tool_response.gitOperation.push.branch` when a `git push` succeeds; an agent that records no gitOperation (Cursor's editor, Codex) is read from the command's own output instead (PushFromOutput), when the command was a `git push`. It is how a session's pull request is found when the session never ran `gh pr` itself (a script opened it). A failed command, or a push without a branch, records nothing.

func WebURL

func WebURL(remote string) (string, bool)

WebURL turns a git remote into the repository's https address.

Accepted: `git@host:owner/repo.git` (scp-like), `ssh://[user@]host[:port]/owner/repo.git`, `git+ssh://`, `git://`, `http(s)://[user[:pass]@]host[:port]/owner/repo(.git)`. Credentials and an ssh port are dropped (the web is on https's own port); an http(s) port is kept. A local path, `file://`, or anything else that names no host returns false.

Types

type PR

type PR struct {
	URL    string `json:"url"`
	Number int    `json:"number"`
	// Title is the `--title` the command passed, when it passed one plainly.
	Title string `json:"title,omitempty"`
	// Action is what this one command did: created, merged, closed, edited,
	// commented. Only a recorded "merged" ever makes a PR read as merged.
	Action string `json:"action"`
}

PR is one pull request a session opened, or merged, as its own tool output recorded it.

func FromToolPost

func FromToolPost(payload []byte) (PR, bool)

FromToolPost reads a pull request out of a Bash tool's PostToolUse payload.

Claude Code records `tool_response.gitOperation.pr` — {number, url, action} — when a `gh pr` command succeeds; that is the primary source and the only one trusted for anything but "created". Without it, a `gh pr create` whose output carries a pull-request URL counts as created. A failed command records nothing.

type Repo

type Repo struct {
	// Root is the repository's top level on this machine, or the directory
	// itself when git could not say. Shown, with a copy button, when there is
	// no web address to link to.
	Root string `json:"root"`
	// URL is the repository's web address, https, no credentials. Empty when
	// there is no remote or it is not a web host (a path, a file:// URL).
	URL string `json:"url,omitempty"`
	// Branch is the checked-out branch; empty on a detached HEAD.
	Branch string `json:"branch,omitempty"`
	// DefaultBranch is the remote's default branch when git knows it locally
	// (refs/remotes/<remote>/HEAD).
	DefaultBranch string `json:"default_branch,omitempty"`
	// BranchURL is the branch's page, set only when the branch is not the
	// default and the host's URL scheme for branches is known.
	BranchURL string `json:"branch_url,omitempty"`
}

Repo is where a working directory's repository lives.

func Lookup

func Lookup(ctx context.Context, dir string) (Repo, bool)

Lookup reads the repository a directory belongs to. It runs git with a short timeout per call; a directory that is not a repository returns a Repo with only Root set and ok=false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL