Skip to main content

Crate vix_git

Crate vix_git 

Source
Expand description

Git integration for Vix.

Two layers:

  • Pure logic (unit-tested, no I/O): parse_status turns git status --porcelain output into FileStatus rows, and diff_marks computes per-line editor-gutter LineMarks between the committed text and the current buffer (via the similar crate).
  • Runners (shell out to the git CLI): is_repo, branch, status, head_blob, and the staging/commit helpers. Using the user’s own git means credential helpers, SSH agents, and hooks all behave exactly as on the command line.

Structs§

BlameLine
One line’s git blame attribution: the short commit hash, author name, YYYY-MM-DD authored date, and the commit summary.
FileStatus
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).
LineMark
A per-line change marker for the editor’s diff gutter.

Functions§

blame_line
git blame for a single 1-based line of a repo-relative path, parsed into a BlameLine. None when not a repo, the path is untracked, or on error.
branch
The current branch name, or None when detached / not a repo. A detached HEAD yields the short commit hash via the caller’s discretion (here None).
checkout
Check out an existing branch (git switch <branch>). Returns Ok(()) on success, or the captured stderr on failure (e.g. a conflicting dirty tree).
commit
Commit the staged changes with message. Returns Ok(()) 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), or None when not a repo or there are no commits yet.
create_branch
Create a new branch and switch to it (git switch -c <name>). Returns Ok(()) 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, or None if 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 into Hunks — maximal runs of adjacent changed lines — in current-line order. Pairs with diff_marks (which colors individual gutter lines).
index_blob
The staged (index) version of rel_path (git show :path), trailing newline preserved. None when the file is not in the index.
is_dirty
Whether the working tree has any staged or unstaged changes (incl. untracked).
is_repo
Whether dir is 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-porcelain output into a BlameLine. Returns None if no header (hash) line is present.
parse_status
Parse git status --porcelain (v1) output into one FileStatus per path.
stage
Stage a path (git add -- <path>). Returns whether the command succeeded.
stage_content
Replace the index entry for rel_path with exactly content (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.