git

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanFastForward

func CanFastForward(path, branch string) bool

CanFastForward returns true if HEAD can be fast-forwarded to origin/branch.

func Clone

func Clone(url, path, token string) error

Clone clones a git repository. If token is non-empty, it is passed as an HTTP authorization header for private repo access.

func CommitsBehind

func CommitsBehind(path, branch string) (int, error)

CommitsBehind returns the number of commits HEAD is behind origin/branch.

func CurrentBranch

func CurrentBranch(path string) (string, error)

CurrentBranch returns the name of the currently checked-out branch.

func FastForward

func FastForward(path string) error

FastForward performs a fast-forward merge from the upstream tracking branch.

func Fetch

func Fetch(path, token string) error

Fetch runs git fetch origin in the given repository. If token is non-empty, it is passed as an HTTP authorization header for private repo access.

func IsClean

func IsClean(path string) bool

IsClean returns true if the working tree has no modifications, staged changes, or untracked files.

func IsRepo

func IsRepo(path string) bool

IsRepo returns true if path contains a .git directory.

func RemoteURL

func RemoteURL(path string) (string, error)

RemoteURL returns the URL of the "origin" remote for the repo at path.

Types

type SyncResult

type SyncResult struct {
	Status  SyncStatus
	Commits int   // Number of commits pulled (only for StatusPulled)
	Error   error // Underlying error (only for StatusError)
}

SyncResult holds the outcome of syncing a repository.

func SyncRepo

func SyncRepo(path, token string) SyncResult

SyncRepo fetches from origin and conditionally fast-forwards. It never modifies a dirty worktree and never does non-fast-forward merges. If token is non-empty, it is passed to git fetch for private repo access.

type SyncStatus

type SyncStatus int

SyncStatus represents the outcome of a sync operation.

const (
	StatusPulled   SyncStatus = iota // Fast-forwarded successfully
	StatusUpToDate                   // Already at latest commit
	StatusFetched                    // Fetched only (dirty worktree or diverged)
	StatusError                      // Operation failed
)

Jump to

Keyboard shortcuts

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