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: PathBufAbsolute 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: OdbLoose object database.
explicit_git_dir: boolDiscovery provenance: true when opened via GIT_DIR env or explicit API.
This suppresses safe.bareRepository implicit checks.
Implementations§
Source§impl Repository
impl Repository
Sourcepub fn open(git_dir: &Path, work_tree: Option<&Path>) -> Result<Self>
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.).
Sourcepub fn discover(start: Option<&Path>) -> Result<Self>
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.
Sourcepub fn index_path(&self) -> PathBuf
pub fn index_path(&self) -> PathBuf
Path to the index file.
Sourcepub fn read_replaced(&self, oid: &ObjectId) -> Result<Object>
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
impl Repository
Sourcepub fn enforce_safe_directory(&self) -> Result<()>
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).
Sourcepub fn enforce_safe_directory_git_dir(&self) -> Result<()>
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).
Sourcepub fn enforce_safe_directory_git_dir_with_path(
&self,
checked: &Path,
) -> Result<()>
pub fn enforce_safe_directory_git_dir_with_path( &self, checked: &Path, ) -> Result<()>
Enforce safe.directory checks against an explicit checked path.