git_info/lib.rs
1#![deny(
2 future_incompatible,
3 keyword_idents,
4 let_underscore,
5 nonstandard_style,
6 unused
7)]
8#![warn(unknown_lints)]
9
10//! # git_info
11//!
12//! Extracts git repository information.
13//!
14//! This library main goal is to provide development/build tools such as
15//! [cargo-make](https://sagiegurari.github.io/cargo-make/)the needed information on the current git repository.
16//!
17//! # Examples
18//!
19//! ```
20//! fn main() {
21//! let info = git_info::get();
22//!
23//! println!("User Name: {}", info.user_name.unwrap_or("Unknown".to_string()));
24//! println!("User Email: {}", info.user_email.unwrap_or("Unknown".to_string()));
25//! println!("Dirty: {}", info.dirty.unwrap_or(false));
26//! println!("Current Branch: {}", info.current_branch.unwrap_or("Unknown".to_string()));
27//! println!("Last Commit Hash: {}", info.head.last_commit_hash.unwrap_or("Unknown".to_string()));
28//! println!("Last Commit Hash (short): {}", info.head.last_commit_hash_short.unwrap_or("Unknown".to_string()));
29//! println!("Config: {:#?}", info.config.unwrap());
30//! println!("Branches: {:#?}", info.branches.unwrap_or(vec![]));
31//! }
32//! ```
33//!
34//! # Installation
35//! In order to use this library, just add it as a dependency:
36//!
37//! ```ini
38//! [dependencies]
39//! git_info = "*"
40//! ```
41//!
42//! # Contributing
43//! See [contributing guide](https://github.com/sagiegurari/git_info/blob/master/.github/CONTRIBUTING.md)
44//!
45//! # License
46//! Developed by Sagie Gur-Ari and licensed under the
47//! [Apache 2](https://github.com/sagiegurari/git_info/blob/master/LICENSE) open source license.
48//!
49
50#[cfg(test)]
51#[path = "./lib_test.rs"]
52mod lib_test;
53
54#[cfg(doctest)]
55doc_comment::doctest!("../README.md");
56
57mod gitinfo;
58pub mod types;
59
60use crate::types::GitInfo;
61
62/// Returns the current git repository information.
63///
64/// # Example
65///
66/// ```
67/// fn main() {
68/// let info = git_info::get();
69///
70/// println!("User Name: {}", info.user_name.unwrap_or("Unknown".to_string()));
71/// println!("User Email: {}", info.user_email.unwrap_or("Unknown".to_string()));
72/// println!("Dirty: {}", info.dirty.unwrap_or(false));
73/// println!("Current Branch: {}", info.current_branch.unwrap_or("Unknown".to_string()));
74/// println!("Last Commit Hash: {}", info.head.last_commit_hash.unwrap_or("Unknown".to_string()));
75/// println!("Last Commit Hash (short): {}", info.head.last_commit_hash_short.unwrap_or("Unknown".to_string()));
76/// println!("Config: {:#?}", info.config.unwrap());
77/// println!("Branches: {:#?}", info.branches.unwrap_or(vec![]));
78/// }
79/// ```
80pub fn get() -> GitInfo {
81 gitinfo::get()
82}