Skip to content

Commit

Permalink
feat: add open::Options::current_dir().
Browse files Browse the repository at this point in the history
That way it's possible to obtain the current working directory
with which the repository was opened.
  • Loading branch information
Byron committed Feb 8, 2024
1 parent 2202c23 commit 04502e3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gix/src/repository/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ impl crate::Repository {
self.options.git_dir_trust.expect("definitely set by now")
}

/// Return the current working directory as present during the instantiation of this repository.
///
/// Note that this should be preferred over manually obtaining it as this may have been adjusted to
/// deal with `core.precomposeUnicode`.
pub fn current_dir(&self) -> &Path {
self.options
.current_dir
.as_deref()
.expect("BUG: cwd is always set after instantiation")
}

/// Returns the main git repository if this is a repository on a linked work-tree, or the `git_dir` itself.
pub fn common_dir(&self) -> &std::path::Path {
self.common_dir.as_deref().unwrap_or_else(|| self.git_dir())
Expand Down

0 comments on commit 04502e3

Please sign in to comment.