pub struct GitRepo { /* private fields */ }Expand description
Repository wrapper.
Implementations§
Source§impl GitRepo
impl GitRepo
Sourcepub fn discover(path: &Path) -> Result<Self>
pub fn discover(path: &Path) -> Result<Self>
Discover and open the repository by searching path and its parents for .git.
Sourcepub fn git_dir(&self) -> &Path
pub fn git_dir(&self) -> &Path
Path to the .git directory (used to compute the cache location).
Sourcepub fn head_ref_name(&self) -> String
pub fn head_ref_name(&self) -> String
Canonical ref name of HEAD (or the short SHA when detached).
Sourcepub fn refs_snapshot(&self) -> Result<Vec<String>>
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.
Sourcepub fn head_commit(&self) -> Result<CommitInfo>
pub fn head_commit(&self) -> Result<CommitInfo>
The commit that HEAD points to.
Sourcepub fn current_branch_name(&self) -> Result<String>
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.)
Collect all tags together with the commits they point to.
Sourcepub fn branch_names(&self) -> Result<Vec<String>>
pub fn branch_names(&self) -> Result<Vec<String>>
Shorthand names of all local and remote branches.
Sourcepub fn commits_between(
&self,
from: Option<&str>,
to: &str,
) -> Result<Vec<CommitInfo>>
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.
Sourcepub fn first_parent_between(
&self,
from: Option<&str>,
to: &str,
) -> Result<Vec<CommitInfo>>
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.
Sourcepub fn merge_base(&self, a: &str, b: &str) -> Result<Option<String>>
pub fn merge_base(&self, a: &str, b: &str) -> Result<Option<String>>
Merge-base of two commits.
Sourcepub fn is_ancestor_of_head(&self, sha: &str) -> Result<bool>
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).
Sourcepub fn is_ancestor_of(&self, ancestor: &str, descendant: &str) -> Result<bool>
pub fn is_ancestor_of(&self, ancestor: &str, descendant: &str) -> Result<bool>
Returns true if ancestor is an ancestor of (or identical to) descendant.
Sourcepub fn changed_paths_for_commit(&self, sha: &str) -> Vec<String>
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.
Sourcepub fn commit_info_of(&self, spec: &str) -> Option<CommitInfo>
pub fn commit_info_of(&self, spec: &str) -> Option<CommitInfo>
Resolve a spec (branch/tag/SHA) to a CommitInfo.
Sourcepub fn local_branch_names(&self) -> Result<Vec<String>>
pub fn local_branch_names(&self) -> Result<Vec<String>>
Sorted list of shorthand local branch names.
Sourcepub fn create_tag(&self, name: &str, target_spec: Option<&str>) -> Result<()>
pub fn create_tag(&self, name: &str, target_spec: Option<&str>) -> Result<()>
Create a lightweight tag on the specified commit (defaults to HEAD).
Sourcepub fn create_branch(&self, name: &str, target_spec: Option<&str>) -> Result<()>
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.
Sourcepub fn clear_cache(&self) -> Result<usize>
pub fn clear_cache(&self) -> Result<usize>
Delete the on-disk cache directory (<.git>/gitversion_cache).
Sourcepub fn uncommitted_changes(&self) -> Result<i64>
pub fn uncommitted_changes(&self) -> Result<i64>
Number of uncommitted changes in the working tree.
Names of tags directly attached to the given commit.
Auto Trait Implementations§
impl !Freeze for GitRepo
impl !RefUnwindSafe for GitRepo
impl !Sync for GitRepo
impl !UnwindSafe for GitRepo
impl Send for GitRepo
impl Unpin for GitRepo
impl UnsafeUnpin for GitRepo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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