Skip to main content

Repository

Struct Repository 

Source
pub struct Repository {
    pub git_dir: PathBuf,
    pub work_tree: Option<PathBuf>,
    pub odb: Odb,
    pub explicit_git_dir: bool,
}
Expand description

A handle to an open Git repository.

Fields§

§git_dir: PathBuf

Absolute path to the git directory (.git/ or bare repo root).

§work_tree: Option<PathBuf>

Absolute path to the working tree, or None for bare repos.

§odb: Odb

Loose object database.

§explicit_git_dir: bool

Discovery provenance: true when opened via GIT_DIR env or explicit API.

This suppresses safe.bareRepository implicit checks.

Implementations§

Source§

impl Repository

Source

pub fn open(git_dir: &Path, work_tree: Option<&Path>) -> Result<Self>

Open a repository from an explicit git-dir and optional work-tree.

§Errors

Returns Error::NotARepository if git_dir does not look like a valid git directory (missing objects/, HEAD, etc.).

Source

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

Discover the repository starting from start (defaults to cwd if None).

Checks GIT_DIR first; if set, uses it directly. Otherwise walks up the directory tree looking for .git (regular directory or gitfile).

§Errors

Returns Error::NotARepository if no repository can be found.

Source

pub fn index_path(&self) -> PathBuf

Path to the index file.

Source

pub fn refs_dir(&self) -> PathBuf

Path to the refs/ directory.

Source

pub fn head_path(&self) -> PathBuf

Path to HEAD.

Source

pub fn is_bare(&self) -> bool

Whether this is a bare repository (no working tree).

Source

pub fn read_replaced(&self, oid: &ObjectId) -> Result<Object>

Read an object, transparently following replace refs.

If refs/replace/<hex> exists for the requested OID and GIT_NO_REPLACE_OBJECTS is not set, this reads the replacement object instead. Otherwise it behaves identically to self.odb.read(oid).

Source§

impl Repository

Source

pub fn enforce_safe_directory(&self) -> Result<()>

Enforce safe.directory ownership checks, matching upstream behavior.

When GIT_TEST_ASSUME_DIFFERENT_OWNER=1, ownership is considered unsafe unless a matching safe.directory value is configured in system/global/ command scopes (repository-local config is ignored).

Source

pub fn enforce_safe_directory_git_dir(&self) -> Result<()>

Enforce safe.directory checks using the repository git-dir path.

Used by operations that explicitly open another repository by path (e.g. local clone source).

Source

pub fn enforce_safe_directory_git_dir_with_path( &self, checked: &Path, ) -> Result<()>

Enforce safe.directory checks against an explicit checked path.

Trait Implementations§

Source§

impl Debug for Repository

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