git

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRepo

func IsRepo(path string) bool

IsRepo returns true if path is inside a git repository.

Types

type CommitInfo

type CommitInfo struct {
	Hash    string
	Author  string
	Date    time.Time
	Message string
}

CommitInfo holds metadata for a single commit.

type FileStatus

type FileStatus struct {
	Path     string
	Staging  StatusCode
	Worktree StatusCode
}

FileStatus represents the git status of a single file.

type PermalinkStyle

type PermalinkStyle int

PermalinkStyle determines the URL format for generated links.

const (
	PermalinkGitHub PermalinkStyle = iota
	PermalinkGitLab
	PermalinkBitbucket
	PermalinkGitea
	PermalinkCodeberg
)

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo wraps a go-git repository with convenience methods.

func Open

func Open(path string) (*Repo, error)

Open opens the git repository at or above the given path. Repeated calls for the same absolute path return a cached Repo.

func (*Repo) Branch

func (r *Repo) Branch() (string, error)

Branch returns the current branch name.

func (*Repo) BranchList

func (r *Repo) BranchList() ([]string, error)

BranchList returns all local branch names.

func (r *Repo) CopyPermalink(filePath string, line int) (string, error)

CopyPermalink generates a permalink and copies it to the clipboard. Returns the link string even if clipboard is unavailable.

func (*Repo) CurrentRemoteURL

func (r *Repo) CurrentRemoteURL() (string, error)

CurrentRemoteURL returns the fetch URL for the "origin" remote.

func (*Repo) FileStatusAt

func (r *Repo) FileStatusAt(relPath string) (FileStatus, error)

FileStatusAt returns the git status for a specific file path relative to the repo root.

func (*Repo) FileURL

func (r *Repo) FileURL(filePath string) (string, error)

FileURL generates a non-permanent URL using the current branch.

func (*Repo) HeadHash

func (r *Repo) HeadHash() (string, error)

HeadHash returns the HEAD commit hash.

func (*Repo) IsClean

func (r *Repo) IsClean() (bool, error)

IsClean returns true if the worktree has no modifications.

func (*Repo) Log

func (r *Repo) Log(n int) ([]CommitInfo, error)

Log returns the last n commits from HEAD.

func (r *Repo) Permalink(filePath string, line int) (string, error)

Permalink generates a permanent URL to a file at a specific commit.

func (*Repo) PermalinkForBranch

func (r *Repo) PermalinkForBranch(filePath string, branch string, line int) (string, error)

PermalinkForBranch generates a URL using a branch name instead of a commit hash.

func (*Repo) PermalinkForRange

func (r *Repo) PermalinkForRange(filePath string, startLine, endLine int) (string, error)

PermalinkForRange generates a permanent URL to a file with a line range.

func (*Repo) Remotes

func (r *Repo) Remotes() (map[string]string, error)

Remotes returns the list of remote names and URLs.

func (*Repo) Root

func (r *Repo) Root() string

Root returns the repository root path.

func (*Repo) Status

func (r *Repo) Status() ([]FileStatus, error)

Status returns the working tree status for all files.

func (*Repo) Tags

func (r *Repo) Tags() ([]string, error)

Tags returns all tag names.

type StatusCode

type StatusCode byte

StatusCode maps to go-git status codes.

const (
	Unmodified StatusCode = ' '
	Modified   StatusCode = 'M'
	Added      StatusCode = 'A'
	Deleted    StatusCode = 'D'
	Renamed    StatusCode = 'R'
	Copied     StatusCode = 'C'
	Untracked  StatusCode = '?'
)

Jump to

Keyboard shortcuts

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