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 ¶
- func Add(ctx context.Context, gitRoot string, paths []string) error
- func AuthorDate(ctx context.Context, gitRoot, rev, path string) (time.Time, error)
- func Available() bool
- func Commit(ctx context.Context, gitRoot, message string) error
- func DirtyPaths(ctx context.Context, gitRoot, dir string) ([]string, error)
- func Fetch(ctx context.Context, gitRoot string) error
- func HasStagedChanges(ctx context.Context, gitRoot string) (bool, error)
- func HasUpstream(ctx context.Context, gitRoot string) bool
- func ListFiles(ctx context.Context, gitRoot, dir string) ([]string, error)
- func MergeBlobs(ctx context.Context, base, ours, theirs []byte) (merged []byte, conflicted bool, err error)
- func MidRebase(ctx context.Context, gitRoot string) bool
- func Push(ctx context.Context, gitRoot string) error
- func Rebase(ctx context.Context, gitRoot, upstream string) (paused bool, err error)
- func RebaseAbort(ctx context.Context, gitRoot string) error
- func RebaseContinue(ctx context.Context, gitRoot string) (paused bool, err error)
- func RebaseSides(ctx context.Context, gitRoot string) (head, rebaseHead string, err error)
- func ShowStage(ctx context.Context, gitRoot string, stage int, path string) ([]byte, error)
- func Tracked(ctx context.Context, gitRoot, path string) bool
- func UnmergedFiles(ctx context.Context, gitRoot string) []string
- func UnpushedCount(ctx context.Context, gitRoot string) (int, error)
- type DirtyEntry
- type Stages
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
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 ¶
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 DirtyPaths ¶
DirtyPaths returns absolute paths under dir that git status reports as dirty. Thin projection of DirtyEntries without the porcelain status code.
func HasStagedChanges ¶
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 ¶
HasUpstream reports whether the current branch has a configured upstream. Any error (no upstream, detached HEAD, no repo) is false.
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 ¶
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 Rebase ¶
Rebase starts git rebase <upstream>. paused is true when the rebase stopped on a conflict.
func RebaseAbort ¶
RebaseAbort runs git rebase --abort.
func RebaseContinue ¶
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 ¶
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 ¶
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 ¶
Tracked reports whether path is in gitRoot's index. Lets a never-committed old path be omitted from pathspec rather than erroring.
func UnmergedFiles ¶
UnmergedFiles lists repo-relative paths currently unmerged (diff-filter=U). Best-effort: empty slice on any error.
Types ¶
type DirtyEntry ¶
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 ¶
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 ¶
ConflictStages enumerates which merge stages exist for path via git ls-files -u. Empty result is not an error — path is not considered conflicted.