Documentation
¶
Overview ¶
Package gitctx reads local git context (current branch, remotes, parsed GitLab project path) so that "auto" composite commands like `gitlab-cli mr create --auto` can derive sensible defaults from cwd.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoGitLabRemote = errors.New("no GitLab remote found")
ErrNoGitLabRemote is returned when no remote URL points at a GitLab-style host.
var ErrNotAGitRepo = errors.New("not a git repository")
ErrNotAGitRepo is returned when the current working directory is not a git repository.
Functions ¶
func CurrentBranch ¶
CurrentBranch returns the current branch name, or empty string if HEAD is detached.
Types ¶
type Context ¶
type Context struct {
Repo string // absolute path to git toplevel; empty if not a repo
CurrentBranch string // empty if detached HEAD or not a repo
Remote *GitLabRemote // nil if no GitLab remote found
}
Context bundles the most useful git context for composite commands.
type GitLabRemote ¶
type GitLabRemote struct {
Host string // e.g. "gitlab.example.com"
ProjectPath string // e.g. "group/subgroup/project" (no .git suffix, no leading slash)
URL string // original URL
}
GitLabRemote describes a parsed remote URL pointing at a GitLab host.
func DetectGitLabRemote ¶
func DetectGitLabRemote(dir string) (*GitLabRemote, error)
DetectGitLabRemote scans the working directory's remotes (in priority order: "origin", "upstream", then any other) and returns the first parsable GitLab remote.
func ParseGitLabRemote ¶
func ParseGitLabRemote(remoteURL string) (*GitLabRemote, error)
ParseGitLabRemote parses an SSH or HTTPS git remote URL into a GitLabRemote. Accepts:
git@gitlab.example.com:group/subgroup/project.git ssh://git@gitlab.example.com:22/group/subgroup/project.git https://gitlab.example.com/group/subgroup/project.git https://oauth2:token@gitlab.example.com/group/subgroup/project.git http://gitlab.example.com/group/project (rare; allowed for local dev)
Returns ErrNoGitLabRemote if the URL is empty or unrecognised.