Skip to main content

GitRepo

Struct GitRepo 

Source
pub struct GitRepo { /* private fields */ }
Expand description

A git repository handle providing typed methods for git operations. All operations shell out to git -C {path} with LC_ALL=C.

Implementations§

Source§

impl GitRepo

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Source

pub fn path(&self) -> &Path

Source

pub fn is_git_repo(&self) -> bool

Check if the path is a git repository (has .git directory or file)

Source

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

Get the default branch name (main or master)

Source

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

Check if the working tree has uncommitted changes

Source

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

Count the number of changed files (staged + unstaged + untracked).

Source

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

Get the current branch name (empty string if detached HEAD)

Source

pub fn ahead_behind(&self, base: &str) -> Result<(u32, u32), GitError>

Get ahead/behind counts relative to a base branch

Source

pub fn worktree_add( &self, path: &Path, branch: &str, base: &str, ) -> Result<(), GitError>

Add a new worktree

Source

pub fn worktree_remove(&self, path: &Path, force: bool) -> Result<(), GitError>

Remove a worktree

Source

pub fn worktree_lock(&self, path: &Path, reason: &str) -> Result<(), GitError>

Lock a worktree with a reason

Source

pub fn worktree_unlock(&self, path: &Path) -> Result<(), GitError>

Unlock a worktree

Source

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

Prune stale worktree entries

Source

pub fn worktree_list(&self) -> Result<Vec<WorktreeEntry>, GitError>

List worktrees using --porcelain format for reliable parsing

Source

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

Delete a local branch

Source

pub fn ref_exists(&self, refspec: &str) -> Result<bool, GitError>

Check if a ref exists (local branch, remote ref, tag, or arbitrary ref).

Source

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

Push a branch and set up tracking

Source

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

Fetch from origin

Source

pub fn resolve_start_point(&self, branch: &str) -> String

Resolve the best available start point for a new worktree. Prefers origin/{branch} (freshest state), falls back to local {branch}. Call after fetch() to ensure remote refs are up-to-date.

Source

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

Pull with rebase from origin

Source

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

Abort a rebase in progress

Source

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

Hard reset to HEAD (discard all staged and unstaged changes)

Source

pub fn reset_hard_to(&self, target: &str) -> Result<(), GitError>

Hard reset to a specific ref

Source

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

Remove untracked files and directories

Source

pub fn rebase(&self, target: &str) -> Result<(), GitError>

Rebase current branch onto a target ref

Source

pub fn add(&self, path: &str) -> Result<(), GitError>

Stage a file

Source

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

Commit with a message

Source

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

Push to origin (current branch)

Source

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

Get the remote URL for origin

Trait Implementations§

Source§

impl Clone for GitRepo

Source§

fn clone(&self) -> GitRepo

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GitRepo

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more