Skip to main content

GitRepo

Struct GitRepo 

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

Repository wrapper.

Implementations§

Source§

impl GitRepo

Source

pub fn discover(path: &Path) -> Result<Self>

Discover and open the repository by searching path and its parents for .git.

Source

pub fn workdir(&self) -> Option<&Path>

Root of the repository working tree.

Source

pub fn git_dir(&self) -> &Path

Path to the .git directory (used to compute the cache location).

Source

pub fn head_ref_name(&self) -> String

Canonical ref name of HEAD (or the short SHA when detached).

Source

pub fn refs_snapshot(&self) -> Result<Vec<String>>

Sorted list of "<name> <target_sha>" for every ref. Used as the refs snapshot in the cache key.

Source

pub fn head_commit(&self) -> Result<CommitInfo>

The commit that HEAD points to.

Source

pub fn current_branch_name(&self) -> Result<String>

Friendly name of the currently checked-out branch.

When HEAD is detached, mirrors the original GitVersion (GitVersionContextFactory) GetBranchesContainingCommit(...).OnlyOrDefault() logic: if a branch has HEAD as its tip (direct match), that branch is used; otherwise the first branch that contains HEAD as a reachable ancestor is used. Exactly one match returns its name; zero or multiple matches return (no branch). (When CI checks out a tag as detached HEAD, HEAD may not be the tip of main, so tip-only matching is insufficient.)

Source

pub fn tags(&self) -> Result<Vec<TagInfo>>

Collect all tags together with the commits they point to.

Source

pub fn branch_names(&self) -> Result<Vec<String>>

Shorthand names of all local and remote branches.

Source

pub fn commits_between( &self, from: Option<&str>, to: &str, ) -> Result<Vec<CommitInfo>>

Returns reachable commits from from (exclusive) to to (inclusive), newest first. When from is None, returns all ancestors of to.

Source

pub fn first_parent_between( &self, from: Option<&str>, to: &str, ) -> Result<Vec<CommitInfo>>

Returns commits from from (exclusive) to to (inclusive) following first parents only, newest first. Used for Mainline trunk traversal.

Source

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

Merge-base of two commits.

Source

pub fn is_ancestor_of_head(&self, sha: &str) -> Result<bool>

Returns true if the given commit is reachable from HEAD (i.e. is an ancestor).

Source

pub fn is_ancestor_of(&self, ancestor: &str, descendant: &str) -> Result<bool>

Returns true if ancestor is an ancestor of (or identical to) descendant.

Source

pub fn changed_paths_for_commit(&self, sha: &str) -> Vec<String>

File paths changed by a commit relative to its first parent. Returns an empty vec for root commits or when the diff cannot be obtained.

Source

pub fn commit_info_of(&self, spec: &str) -> Option<CommitInfo>

Resolve a spec (branch/tag/SHA) to a CommitInfo.

Source

pub fn local_branch_names(&self) -> Result<Vec<String>>

Sorted list of shorthand local branch names.

Source

pub fn create_tag(&self, name: &str, target_spec: Option<&str>) -> Result<()>

Create a lightweight tag on the specified commit (defaults to HEAD).

Source

pub fn create_branch(&self, name: &str, target_spec: Option<&str>) -> Result<()>

Create a branch ref on the specified commit (defaults to HEAD). Does not touch the working tree.

Source

pub fn clear_cache(&self) -> Result<usize>

Delete the on-disk cache directory (<.git>/gitversion_cache).

Source

pub fn uncommitted_changes(&self) -> Result<i64>

Number of uncommitted changes in the working tree.

Source

pub fn tags_on_commit(&self, sha: &str) -> Result<HashSet<String>>

Names of tags directly attached to the given commit.

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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