gix_discover/
lib.rs

1//! Find git repositories or search them upwards from a starting point, or determine if a directory looks like a git repository.
2//!
3//! Note that detection methods are educated guesses using the presence of files, without looking too much into the details.
4#![deny(missing_docs, rust_2018_idioms)]
5#![forbid(unsafe_code)]
6
7/// The name of the `.git` directory.
8pub const DOT_GIT_DIR: &str = ".git";
9
10/// The name of the `modules` sub-directory within a `.git` directory for keeping submodule checkouts.
11pub const MODULES: &str = "modules";
12
13///
14pub mod repository;
15
16///
17pub mod is_git {
18    use std::path::PathBuf;
19
20    /// The error returned by [`crate::is_git()`].
21    #[derive(Debug, thiserror::Error)]
22    #[allow(missing_docs)]
23    pub enum Error {
24        #[error("Could not find a valid HEAD reference")]
25        FindHeadRef(#[from] gix_ref::file::find::existing::Error),
26        #[error("Missing HEAD at '.git/HEAD'")]
27        MissingHead,
28        #[error("Expected HEAD at '.git/HEAD', got '.git/{}'", .name)]
29        MisplacedHead { name: bstr::BString },
30        #[error("Expected an objects directory at '{}'", .missing.display())]
31        MissingObjectsDirectory { missing: PathBuf },
32        #[error("The worktree's private repo's commondir file at '{}' or it could not be read", .missing.display())]
33        MissingCommonDir { missing: PathBuf, source: std::io::Error },
34        #[error("Expected a refs directory at '{}'", .missing.display())]
35        MissingRefsDirectory { missing: PathBuf },
36        #[error(transparent)]
37        GitFile(#[from] crate::path::from_gitdir_file::Error),
38        #[error("Could not retrieve metadata of \"{path}\"")]
39        Metadata { source: std::io::Error, path: PathBuf },
40        #[error("The repository's config file doesn't exist or didn't have a 'bare' configuration or contained core.worktree without value")]
41        Inconclusive,
42        #[error("Could not obtain current directory for resolving the '.' repository path")]
43        CurrentDir(#[from] std::io::Error),
44    }
45}
46
47mod is;
48pub use is::{bare as is_bare, git as is_git, submodule_git_dir as is_submodule_git_dir};
49
50///
51pub mod upwards;
52pub use upwards::function::{discover as upwards, discover_opts as upwards_opts};
53
54///
55pub mod path;
56
57///
58pub mod parse;