Function grev::git_revision_bare

source ·
pub fn git_revision_bare<D>(directory: D) -> Result<Option<String>>where
    D: AsRef<Path>,
Expand description

Retrieve a git revision identifier that either includes the tag we are on or the shortened SHA-1.

This function is meant to be run from a Cargo build script. It takes care of printing necessary rerun-if-changed directives to the provided writer. As a result, callers are advised to invoke it only once and cache the result.

The provided directory is a path expected to point somewhere into the git repository in question. Typically, it can simply be set to the value of the CARGO_MANIFEST_DIR variable, as set by Cargo.

The function works on a best-effort basis: if git is not available or no git repository is present, it will fail gracefully by returning Ok(None).

Notes

Compared to git_revision_auto, the revision identifier produced by this function does not include any indication of local changes (+).