Skip to main content

Git

Struct Git 

Source
pub struct Git {
    pub dir: PathBuf,
}
Expand description

A git handle rooted at one directory (the primary checkout or a worktree).

Fields§

§dir: PathBuf

Implementations§

Source§

impl Git

Source

pub fn new(dir: impl Into<PathBuf>) -> Git

Source

pub fn at(&self, dir: impl Into<PathBuf>) -> Git

Source

pub fn primary_root(&self) -> Result<PathBuf, GitError>

Primary checkout root via rev-parse --git-common-dir; bare rejected.

Source

pub fn rev_parse(&self, rev: &str) -> Result<String, GitError>

Source

pub fn short_head(&self) -> Result<String, GitError>

Source

pub fn verify_ref(&self, name: &str) -> Result<Option<String>, GitError>

rev-parse -q --verify <ref>; None when the ref does not exist.

Source

pub fn current_branch(&self) -> Result<Option<String>, GitError>

Current branch short name; None when detached.

Source

pub fn origin_head_branch(&self) -> Result<Option<String>, GitError>

origin/HEAD target branch name (main from origin/main).

Source

pub fn user_email(&self) -> Result<Option<String>, GitError>

Source

pub fn has_origin(&self) -> Result<bool, GitError>

Source

pub fn fetch_origin(&self, branch: &str) -> Result<bool, GitError>

Source

pub fn merge_base(&self, a: &str, b: &str) -> Result<String, GitError>

Source

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.

Source

pub fn index_differs_from(&self, rev: &str) -> Result<Vec<String>, GitError>

Paths whose entry in the index differs from rev.

Source

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.

Source

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.

Source

pub fn is_ancestor(&self, a: &str, b: &str) -> Result<bool, GitError>

Source

pub fn status_porcelain(&self) -> Result<String, GitError>

Source

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.

Source

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.

Source

pub fn clean_against(&self, rev: &str) -> Result<bool, GitError>

git diff --quiet <rev> + --cached: clean against a commit.

Source

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.

Source

pub fn common_dir(&self) -> Result<PathBuf, GitError>

The shared .git directory of this repository (the primary checkout’s, also from inside a worktree).

Source

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.

Source

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.

Source

pub fn commit_message(&self, rev: &str) -> Result<String, GitError>

The full message of a commit (log -1 --format=%B).

Source

pub fn conflicted_paths(&self) -> Vec<String>

Paths with unresolved merge conflicts in this worktree.

Source

pub fn added_or_modified( &self, from: &str, to: &str, ) -> Result<Vec<String>, GitError>

Paths added or modified between two commits (deletions left out).

Source

pub fn worktree_add( &self, path: &Path, rev: &str, detach: bool, ) -> Result<(), GitError>

Source

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.

Source

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.

Source

pub fn reset_hard(&self, rev: &str) -> Result<(), GitError>

Source

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.

Source

pub fn clean_fdq(&self) -> Result<(), GitError>

Source

pub fn create_branch(&self, name: &str, rev: &str) -> Result<(), GitError>

Source

pub fn delete_branch(&self, name: &str) -> Result<(), GitError>

Source

pub fn branch_exists(&self, name: &str) -> Result<bool, GitError>

Source

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, …).

Source

pub fn add_all(&self) -> Result<(), GitError>

Source

pub fn commit(&self, message: &str) -> Result<(), GitError>

Commit with the committer fallback vitrify <vitrify@local> when user.email is unset.

Source

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.

Source

pub fn restore_paths(&self, rev: &str, paths: &[String]) -> Result<(), GitError>

Copy paths as they are at rev into this worktree, left unstaged.

Source

pub fn merge_no_ff(&self, branch: &str, message: &str) -> Result<(), GitError>

Source

pub fn merge_abort(&self) -> Result<(), GitError>

Source

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.

Source

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.

Source

pub fn log_oneline(&self, n: usize) -> Result<String, GitError>

Trait Implementations§

Source§

impl Clone for Git

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Git

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Git

§

impl Freeze for Git

§

impl Move for Git

§

impl RefUnwindSafe for Git

§

impl Send for Git

§

impl Sync for Git

§

impl Unpin for Git

§

impl UnsafeUnpin for Git

§

impl UnwindSafe for Git

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.