Thanks to visit codestin.com
Credit goes to docs.rs

Skip to main content

discover

Function discover 

Source
pub fn discover(directory: impl AsRef<Path>) -> Result<Repository, Error>
Expand description

Try to open a git repository in directory and search upwards through its parents until one is found, using default trust options which matters in case the found repository isn’t owned by the current user.

For details, see ThreadSafeRepository::discover().

§Note

The discovered repository might not be suitable for any operation that requires authentication with remotes as it doesn’t see the relevant git configuration.

To achieve that, one has to enable git_binary configuration in the open-options and use ThreadSafeRepository::discover_opts() instead. Alternatively, it might be well-known that the tool is going to run in a neatly configured environment without relying on bundled configuration.

§Examples

let repo = doctest::discover_repo(repo_dir.join("some/very/deeply/nested/subdir"))?;

assert_eq!(repo.kind(), gix::repository::Kind::Common);
assert_eq!(repo.head_name()?.expect("born").shorten(), "main");
assert!(repo.workdir_path("this").expect("non-bare").is_file());