git

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package git wraps the external git binary for path-scoped staging, commits, porcelain status, and mid-rebase detection. Commands run with cmd.Dir set to a caller-supplied git-root; tk never writes under .git/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(ctx context.Context, gitRoot string, paths []string) error

Add stages exactly the given pathspecs — never the whole tree. Staging specific paths leaves unrelated dirty files untouched and records deletions of tracked-but-gone paths.

func AuthorDate

func AuthorDate(ctx context.Context, gitRoot, rev, path string) (time.Time, error)

AuthorDate returns the author date of the last commit on rev that touched path. Per-file, never branch-tip, so an unrelated later commit cannot decide another ticket's fields. Empty when no commit touched path (zero time).

func Available

func Available() bool

Available reports whether the git binary is on PATH. Callers treat absence like a missing git-root: writes still land, commit is skipped.

func Commit

func Commit(ctx context.Context, gitRoot, message string) error

Commit records the staged changes with the given fixed message. Never pushes.

func DirtyPaths

func DirtyPaths(ctx context.Context, gitRoot, dir string) ([]string, error)

DirtyPaths returns absolute paths under dir that git status reports as dirty. Thin projection of DirtyEntries without the porcelain status code.

func Fetch

func Fetch(ctx context.Context, gitRoot string) error

Fetch updates remote-tracking refs (git fetch).

func HasStagedChanges

func HasStagedChanges(ctx context.Context, gitRoot string) (bool, error)

HasStagedChanges reports whether the index differs from HEAD. Self-commit checks before committing so a byte-identical rewrite is a clean no-op.

func HasUpstream

func HasUpstream(ctx context.Context, gitRoot string) bool

HasUpstream reports whether the current branch has a configured upstream. Any error (no upstream, detached HEAD, no repo) is false.

func ListFiles

func ListFiles(ctx context.Context, gitRoot, dir string) ([]string, error)

ListFiles lists index-tracked paths under dir via git ls-files, repo-relative.

func MergeBlobs

func MergeBlobs(ctx context.Context, base, ours, theirs []byte) (merged []byte, conflicted bool, err error)

MergeBlobs 3-way text-merges three in-memory blobs with git merge-file. Returns the merged bytes and whether conflict markers were left.

func MidRebase

func MidRebase(ctx context.Context, gitRoot string) bool

MidRebase reports whether gitRoot is mid-rebase (rebase-merge or rebase-apply). Resolves the git dir via rev-parse so worktrees and submodules are correct; probe errors return false so callers refuse only on affirmative true.

func Push

func Push(ctx context.Context, gitRoot string) error

Push runs git push to the current branch's upstream.

func Rebase

func Rebase(ctx context.Context, gitRoot, upstream string) (paused bool, err error)

Rebase starts git rebase <upstream>. paused is true when the rebase stopped on a conflict.

func RebaseAbort

func RebaseAbort(ctx context.Context, gitRoot string) error

RebaseAbort runs git rebase --abort.

func RebaseContinue

func RebaseContinue(ctx context.Context, gitRoot string) (paused bool, err error)

RebaseContinue runs git rebase --continue. paused is true on a later conflict. Editor is disabled so the commit message is reused non-interactively.

func RebaseSides

func RebaseSides(ctx context.Context, gitRoot string) (head, rebaseHead string, err error)

RebaseSides resolves the two side revs of a paused rebase: HEAD (stage :2) and REBASE_HEAD (stage :3). Mapping is inverted from everyday "ours"/"theirs" during rebase.

func ShowStage

func ShowStage(ctx context.Context, gitRoot string, stage int, path string) ([]byte, error)

ShowStage returns the raw blob of one conflict stage via git show :<stage>:<path>. Callers must enumerate with ConflictStages first; a non-zero exit is a genuine fault.

func Tracked

func Tracked(ctx context.Context, gitRoot, path string) bool

Tracked reports whether path is in gitRoot's index. Lets a never-committed old path be omitted from pathspec rather than erroring.

func UnmergedFiles

func UnmergedFiles(ctx context.Context, gitRoot string) []string

UnmergedFiles lists repo-relative paths currently unmerged (diff-filter=U). Best-effort: empty slice on any error.

func UnpushedCount

func UnpushedCount(ctx context.Context, gitRoot string) (int, error)

UnpushedCount returns how many commits the current branch is ahead of its upstream.

Types

type DirtyEntry

type DirtyEntry struct {
	Path string
	Code string
}

DirtyEntry is one dirty path under a scope dir plus its two-character porcelain status code.

func DirtyEntries

func DirtyEntries(ctx context.Context, gitRoot, dir string) ([]DirtyEntry, error)

DirtyEntries returns dirty paths under dir with porcelain status codes. Rename/copy entries contribute their destination path.

type Stages

type Stages struct {
	Base   bool
	Ours   bool
	Theirs bool
}

Stages reports which of a conflicted path's three merge stages exist in the index. A missing stage is normal (add/add has no :1; delete/modify lacks the deleting side); enumerating before reading keeps genuine git-show failures from looking like deletions.

func ConflictStages

func ConflictStages(ctx context.Context, gitRoot, path string) (Stages, error)

ConflictStages enumerates which merge stages exist for path via git ls-files -u. Empty result is not an error — path is not considered conflicted.

func (Stages) Any

func (s Stages) Any() bool

Any reports whether any conflict stage is present.

Jump to

Keyboard shortcuts

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