Expand description
Git integration for Vix.
Two layers:
- Pure logic (unit-tested, no I/O):
parse_statusturnsgit status --porcelainoutput intoFileStatusrows, anddiff_markscomputes per-line editor-gutterLineMarks between the committed text and the current buffer (via thesimilarcrate). - Runners (shell out to the
gitCLI):is_repo,branch,status,head_blob, and the staging/commit helpers. Using the user’s owngitmeans credential helpers, SSH agents, and hooks all behave exactly as on the command line.
Structs§
- Blame
Line - One line’s
git blameattribution: the short commit hash, author name,YYYY-MM-DDauthored date, and the commit summary. - File
Status - One changed path from
git status, with its staged (index) and unstaged (working-tree) change, if any. - Hunk
- A contiguous changed region between the committed text and the current buffer, for hunk navigation and revert.
Enums§
- Change
- A kind of change to a file (in the index or the working tree).
- Line
Mark - A per-line change marker for the editor’s diff gutter.
Functions§
- blame_
line git blamefor a single 1-based line of a repo-relative path, parsed into aBlameLine.Nonewhen not a repo, the path is untracked, or on error.- branch
- The current branch name, or
Nonewhen detached / not a repo. A detached HEAD yields the short commit hash via the caller’s discretion (hereNone). - checkout
- Check out an existing branch (
git switch <branch>). ReturnsOk(())on success, or the captured stderr on failure (e.g. a conflicting dirty tree). - commit
- Commit the staged changes with
message. ReturnsOk(())on success, or the captured stderr on failure (e.g. nothing staged, hook rejected). - commit_
amend - Amend the previous commit, folding in currently-staged changes and keeping
its message (
git commit --amend --no-edit). - commit_
count - The number of commits reachable from HEAD (
git rev-list --count HEAD), orNonewhen not a repo or there are no commits yet. - create_
branch - Create a new branch and switch to it (
git switch -c <name>). ReturnsOk(())on success, or the captured stderr on failure (e.g. the name already exists or is invalid). - diff_
marks - Compute per-line gutter marks between the committed text (
head) and the current buffer (current), keyed by current line index (0-based). - head_
blob - The committed (
HEAD) contents of a repo-relative path, orNoneif the path is not in HEAD (newly added/untracked) or on any error. - hunks
- Group the line diff between committed text (
head) and the current buffer intoHunks — maximal runs of adjacent changed lines — in current-line order. Pairs withdiff_marks(which colors individual gutter lines). - index_
blob - The staged (index) version of
rel_path(git show :path), trailing newline preserved.Nonewhen the file is not in the index. - is_
dirty - Whether the working tree has any staged or unstaged changes (incl. untracked).
- is_repo
- Whether
diris inside a git working tree. - local_
branches - The local branch names, current branch first when it can be determined.
- parse_
blame_ porcelain - Parse one entry of
git blame --line-porcelainoutput into aBlameLine. ReturnsNoneif no header (hash) line is present. - parse_
status - Parse
git status --porcelain(v1) output into oneFileStatusper path. - stage
- Stage a path (
git add -- <path>). Returns whether the command succeeded. - stage_
content - Replace the index entry for
rel_pathwith exactlycontent(used to stage a single hunk): hash the content into a blob and point the index at it, keeping the working tree untouched. - stash_
pop - Restore the most recent stash (
git stash pop). - stash_
push - Stash the working tree and index (
git stash push). - status
- The changed files reported by
git status --porcelain. - unstage
- Unstage a path (
git restore --staged -- <path>). Returns success.