Documentation
¶
Index ¶
- func CommitStaged(dir, msg string) error
- func DiffFile(dir, path string, staged bool) (string, error)
- func HasStaged(dir string) bool
- func IsRepo(dir string) bool
- func ShowCommit(dir, sha string) (string, error)
- func Stage(dir string, paths []string) error
- func Unstage(dir string, paths []string) error
- type Commit
- type FileStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitStaged ¶ added in v0.26.0
CommitStaged commits the currently staged changes with the given message. It uses a local identity override so it works in repos without user.name/ user.email configured. Returns an error when nothing is staged.
func DiffFile ¶ added in v0.26.0
DiffFile returns the raw unified diff for path. When staged is true it diffs the index (cached) instead of the working tree. Returns "" when the file has no changes at the requested level. Uses --no-color.
Untracked files (git status "??") are diffed with `git diff --no-index /dev/null -- path` so that a brand-new file renders as an all-addition hunk instead of the empty string plain `git diff` returns for untracked paths. Staged untracked files are handled by the normal --cached path.
func ShowCommit ¶ added in v0.26.0
ShowCommit returns the full unified diff for the given commit (raw text from `git show --no-color`).
Types ¶
type Commit ¶ added in v0.26.0
type Commit struct {
SHA string `json:"sha"`
Short string `json:"short"`
Message string `json:"message"` // subject line only
Author string `json:"author"`
Time string `json:"time"` // ISO 8601
}
Commit is one entry from `git log --format=...`.
type FileStatus ¶ added in v0.26.0
type FileStatus struct {
Path string `json:"path"` // workspace-relative
X string `json:"x"` // index/staged state code, e.g. "M", "A", " ", "?"
Y string `json:"y"` // worktree state code
Staged bool `json:"staged"` // true when X is non-blank and not "?"
}
FileStatus is one entry from `git status --porcelain`.
func Status ¶ added in v0.26.0
func Status(dir string) ([]FileStatus, error)
Status returns the working-tree status of dir as a list of FileStatus entries (one per changed file). Returns nil, nil when the tree is clean. Returns nil, nil (not an error) when dir is not a git repository.