Skip to main content

GitContext

Struct GitContext 

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

Represents a directory and selected commit within a Git repository.

Implementations§

Source§

impl GitContext

Source

pub fn create( path: impl AsRef<Path>, committish: Option<&str>, engine: GitEngine, ) -> Result<Self>

Discovers a repository from path or one of its ancestors.

Git’s own discovery is used, so linked worktrees and textual .git files are supported. A path outside a repository produces a usable GitContextKind::NoRepository context. Bare repositories are rejected because version calculation requires a working tree.

Source

pub fn create_with_environment( path: impl AsRef<Path>, committish: Option<&str>, default_engine: GitEngine, ) -> Result<Self>

Creates a context using the effective engine selected by environment policy.

Source

pub fn kind(&self) -> GitContextKind

Gets the kind of context that was created.

Source

pub fn engine(&self) -> GitEngine

Gets the requested Git engine.

Source

pub fn is_repository(&self) -> bool

Gets whether an actual repository backs this context.

Source

pub fn working_tree_path(&self) -> &Path

Gets the absolute root of the working tree.

Source

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

Gets the repository metadata directory. In a linked worktree this is the worktree-specific Git directory, not necessarily <working tree>/.git.

Source

pub fn repo_relative_project_directory(&self) -> &Path

Gets the directory selected for version calculation, relative to the working tree.

Source

pub fn set_repo_relative_project_directory( &mut self, directory: impl AsRef<Path>, ) -> Result<()>

Selects the directory used by higher version-file layers.

Source

pub fn absolute_project_directory(&self) -> PathBuf

Gets the absolute directory selected for version calculation.

Source

pub fn repository(&self) -> Option<&Repository>

Exposes the repository to the future version-file and history layers.

Source

pub fn git_commit_id(&self) -> Option<Oid>

Gets the selected commit ID.

Source

pub fn is_head(&self) -> Result<bool>

Gets whether the selected commit is the commit at HEAD.

Source

pub fn git_commit_dates(&self) -> Result<Option<CommitDates>>

Gets the selected commit’s author and committer timestamps.

Source

pub fn head_canonical_name(&self) -> Result<Option<String>>

Gets the canonical name of HEAD, such as refs/heads/main.

A detached HEAD is reported as HEAD; an unborn repository has no name.

Source

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

Gets canonical tag names that resolve to the selected commit.

Annotated tags are peeled before comparison.

Source

pub fn is_shallow(&self) -> bool

Gets whether the repository is shallow.

libgit2 checks the common repository directory, which also handles linked worktrees correctly.

Source

pub fn is_working_tree_dirty(&self) -> Result<bool>

Gets whether tracked, untracked, or staged working-tree changes exist.

Source

pub fn is_ignored(&self, path: impl AsRef<Path>) -> Result<bool>

Determines whether Git would ignore path.

Source

pub fn try_select_commit(&mut self, committish: &str) -> Result<bool>

Attempts to select a commit using any revparse-compatible committish.

Tags (including annotated tags), local and remote branches, abbreviated IDs, and first-parent expressions such as HEAD~2 are accepted.

Source

pub fn apply_tag(&self, name: &str) -> Result<Oid>

Creates a lightweight tag at the selected commit.

Source

pub fn stage(&self, path: impl AsRef<Path>) -> Result<()>

Adds a path to the index and writes the updated index.

Source

pub fn short_unique_commit_id(&self, min_length: usize) -> Result<String>

Gets the shortest object ID of at least min_length characters that uniquely identifies the selected commit in this object database.

Source

pub fn short_unique_id( &self, commit_id: Oid, min_length: usize, ) -> Result<String>

Gets a shortest unique ID for an arbitrary commit.

Source

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

Detects the repository’s default branch using remote HEADs, local configuration, and conventional names, in that order.

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