pub struct Git {
pub dir: PathBuf,
}Expand description
A git handle rooted at one directory (the primary checkout or a worktree).
Fields§
§dir: PathBufImplementations§
Source§impl Git
impl Git
pub fn new(dir: impl Into<PathBuf>) -> Git
pub fn at(&self, dir: impl Into<PathBuf>) -> Git
Sourcepub fn primary_root(&self) -> Result<PathBuf, GitError>
pub fn primary_root(&self) -> Result<PathBuf, GitError>
Primary checkout root via rev-parse --git-common-dir; bare rejected.
pub fn rev_parse(&self, rev: &str) -> Result<String, GitError>
pub fn short_head(&self) -> Result<String, GitError>
Sourcepub fn verify_ref(&self, name: &str) -> Result<Option<String>, GitError>
pub fn verify_ref(&self, name: &str) -> Result<Option<String>, GitError>
rev-parse -q --verify <ref>; None when the ref does not exist.
Sourcepub fn current_branch(&self) -> Result<Option<String>, GitError>
pub fn current_branch(&self) -> Result<Option<String>, GitError>
Current branch short name; None when detached.
Sourcepub fn origin_head_branch(&self) -> Result<Option<String>, GitError>
pub fn origin_head_branch(&self) -> Result<Option<String>, GitError>
origin/HEAD target branch name (main from origin/main).
pub fn user_email(&self) -> Result<Option<String>, GitError>
pub fn has_origin(&self) -> Result<bool, GitError>
pub fn fetch_origin(&self, branch: &str) -> Result<bool, GitError>
pub fn merge_base(&self, a: &str, b: &str) -> Result<String, GitError>
Sourcepub fn object_ids(
&self,
names: &[String],
) -> Result<Vec<Option<String>>, GitError>
pub fn object_ids( &self, names: &[String], ) -> Result<Vec<Option<String>>, GitError>
The object each of names (<rev>:<path>, <rev>^{commit}, …)
names, in order, None where there is none: one git cat-file --batch-check for all of them.
Sourcepub fn changed_paths(
&self,
from: &str,
to: &str,
) -> Result<Vec<String>, GitError>
pub fn changed_paths( &self, from: &str, to: &str, ) -> Result<Vec<String>, GitError>
Repo-relative paths that differ between two commits (git diff --name-only --no-renames -z): a rename lists both its sides.
Sourcepub fn index_differs_from(&self, rev: &str) -> Result<Vec<String>, GitError>
pub fn index_differs_from(&self, rev: &str) -> Result<Vec<String>, GitError>
Paths whose entry in the index differs from rev.
Sourcepub fn committable_files(
&self,
roots: &[String],
) -> Result<Vec<String>, GitError>
pub fn committable_files( &self, roots: &[String], ) -> Result<Vec<String>, GitError>
The files under roots that git would commit — tracked, or untracked
and not ignored (ls-files --cached --others --exclude-standard) —
present on disk, relative to this directory; per root in order,
sorted (. lists everything). Nested repositories and anything under
.git or .vitrify are left out. What git ignores is never part of
the governed tree or an SDD candidate, whatever the ecosystem.
Sourcepub fn show_text(
&self,
rev: &str,
path: &str,
) -> Result<Option<String>, GitError>
pub fn show_text( &self, rev: &str, path: &str, ) -> Result<Option<String>, GitError>
A file’s exact text at a commit (git show <rev>:<path>); None when
the path is absent there or is not UTF-8.
pub fn is_ancestor(&self, a: &str, b: &str) -> Result<bool, GitError>
pub fn status_porcelain(&self) -> Result<String, GitError>
Sourcepub fn changes_readonly(&self) -> Result<Vec<(String, String)>, GitError>
pub fn changes_readonly(&self) -> Result<Vec<(String, String)>, GitError>
Every changed or untracked path as (XY, path), without taking the
index lock: run status probes worktrees whose workers may be
running git at the same moment.
Sourcepub fn numstat_readonly(&self, rev: &str) -> Result<(u64, u64), GitError>
pub fn numstat_readonly(&self, rev: &str) -> Result<(u64, u64), GitError>
Lines added and removed against rev in the working tree, without
taking the index lock. Binary files (-) count as 0.
Sourcepub fn clean_against(&self, rev: &str) -> Result<bool, GitError>
pub fn clean_against(&self, rev: &str) -> Result<bool, GitError>
git diff --quiet <rev> + --cached: clean against a commit.
Sourcepub fn is_dirty(&self) -> Result<bool, GitError>
pub fn is_dirty(&self) -> Result<bool, GitError>
Whether the working tree or index differs from HEAD, or holds
untracked files git does not ignore.
Sourcepub fn common_dir(&self) -> Result<PathBuf, GitError>
pub fn common_dir(&self) -> Result<PathBuf, GitError>
The shared .git directory of this repository (the primary
checkout’s, also from inside a worktree).
Sourcepub fn ignored_by(&self, path: &str) -> Result<Option<String>, GitError>
pub fn ignored_by(&self, path: &str) -> Result<Option<String>, GitError>
The ignore rule that covers path (repo-relative), as
<file>:<line> (<pattern>) — None when git does not ignore it.
Rules in .gitignore files outrank .git/info/exclude, so a hit in
the latter means no in-tree ignore file matched.
Sourcepub fn exclude_locally(&self, pattern: &str) -> Result<(), GitError>
pub fn exclude_locally(&self, pattern: &str) -> Result<(), GitError>
Add pattern to .git/info/exclude unless it is already there —
ignoring a path for this clone only, with no ignore file in the tree.
Sourcepub fn commit_message(&self, rev: &str) -> Result<String, GitError>
pub fn commit_message(&self, rev: &str) -> Result<String, GitError>
The full message of a commit (log -1 --format=%B).
Sourcepub fn conflicted_paths(&self) -> Vec<String>
pub fn conflicted_paths(&self) -> Vec<String>
Paths with unresolved merge conflicts in this worktree.
Sourcepub fn added_or_modified(
&self,
from: &str,
to: &str,
) -> Result<Vec<String>, GitError>
pub fn added_or_modified( &self, from: &str, to: &str, ) -> Result<Vec<String>, GitError>
Paths added or modified between two commits (deletions left out).
pub fn worktree_add( &self, path: &Path, rev: &str, detach: bool, ) -> Result<(), GitError>
Sourcepub fn worktree_add_branch(
&self,
path: &Path,
branch: &str,
rev: &str,
) -> Result<(), GitError>
pub fn worktree_add_branch( &self, path: &Path, branch: &str, rev: &str, ) -> Result<(), GitError>
A new worktree at path on a new branch forked from rev. Fails —
and changes nothing — when the path or the branch already exists.
Sourcepub fn worktree_remove(&self, path: &Path) -> Result<(), GitError>
pub fn worktree_remove(&self, path: &Path) -> Result<(), GitError>
Remove a worktree. git worktree remove forgets it too; only when
that fails (the directory was already gone) is the list pruned — a
prune looks at every worktree, including one another process is in
the middle of adding.
pub fn reset_hard(&self, rev: &str) -> Result<(), GitError>
Sourcepub fn fast_forward_tree(&self, old: &str, new: &str) -> Result<(), GitError>
pub fn fast_forward_tree(&self, old: &str, new: &str) -> Result<(), GitError>
Bring index and working tree from old to new the way a
fast-forward does (read-tree -m -u): files that differ between the
two are updated, everything else — local changes included — is kept;
a file with local changes, or an untracked file, in the way of an
update makes it fail with nothing touched. For a checkout whose
branch ref has already been moved to new. The index is refreshed
first: without that a file merely touched since it was last read
counts as changed.
pub fn clean_fdq(&self) -> Result<(), GitError>
Sourcepub fn clean_all(&self) -> Result<(), GitError>
pub fn clean_all(&self) -> Result<(), GitError>
Remove every file git does not track, ignored ones included, and
nested repositories too (clean -ffdx).
pub fn create_branch(&self, name: &str, rev: &str) -> Result<(), GitError>
pub fn delete_branch(&self, name: &str) -> Result<(), GitError>
pub fn branch_exists(&self, name: &str) -> Result<bool, GitError>
Sourcepub fn branches_under(&self, prefix: &str) -> Result<Vec<String>, GitError>
pub fn branches_under(&self, prefix: &str) -> Result<Vec<String>, GitError>
Short names of the local branches under prefix (sdd/x/U-001
lists sdd/x/U-001/c1, sdd/x/U-001/c2, …).
pub fn add_all(&self) -> Result<(), GitError>
Sourcepub fn commit(&self, message: &str) -> Result<(), GitError>
pub fn commit(&self, message: &str) -> Result<(), GitError>
Commit with the committer fallback vitrify <vitrify@local> when
user.email is unset.
Sourcepub fn commit_note(&self, subject: &str, body: &str) -> Result<(), GitError>
pub fn commit_note(&self, subject: &str, body: &str) -> Result<(), GitError>
Commit whatever is staged — nothing, if nothing is — under subject
with body as the rest of the message. Used to leave a note on a
branch whose work is being set aside.
Sourcepub fn restore_paths(&self, rev: &str, paths: &[String]) -> Result<(), GitError>
pub fn restore_paths(&self, rev: &str, paths: &[String]) -> Result<(), GitError>
Copy paths as they are at rev into this worktree, left unstaged.
pub fn merge_no_ff(&self, branch: &str, message: &str) -> Result<(), GitError>
pub fn merge_abort(&self) -> Result<(), GitError>
Sourcepub fn update_ref_cas(
&self,
refname: &str,
new: &str,
old: &str,
) -> Result<(), GitError>
pub fn update_ref_cas( &self, refname: &str, new: &str, old: &str, ) -> Result<(), GitError>
The CAS: update-ref refs/heads/<mainline> <new> <old> — updates only
if the current value is <old>; rejection is a typed LostRace.
Sourcepub fn push_cas(&self, new: &str, mainline: &str) -> Result<(), GitError>
pub fn push_cas(&self, new: &str, mainline: &str) -> Result<(), GitError>
push origin <new>:refs/heads/<mainline>; a push rejection is a
typed LostRace, any other failure is an error.
pub fn log_oneline(&self, n: usize) -> Result<String, GitError>
Sourcepub fn first_parent_range(
&self,
from: &str,
to: &str,
) -> Result<Vec<String>, GitError>
pub fn first_parent_range( &self, from: &str, to: &str, ) -> Result<Vec<String>, GitError>
The commits on the first-parent chain of to that from does not
reach, oldest first (rev-list --first-parent --reverse from..to).
Sourcepub fn subject(&self, rev: &str) -> Result<String, GitError>
pub fn subject(&self, rev: &str) -> Result<String, GitError>
The subject line of a commit (log -1 --format=%s).