Reading git config from global and the containing repo in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env run-cargo-script | |
//! This is a regular crate doc comment, but it also contains a partial | |
//! Cargo manifest. Note the use of a *fenced* code block, and the | |
//! `cargo` "language". | |
//! | |
//! ```cargo | |
//! [dependencies] | |
//! git2 = "0.13" | |
//! ``` | |
extern crate git2; | |
use git2::{Repository,Config}; | |
use std::env; | |
fn main() { | |
let repo = match Repository::discover(env::current_dir().unwrap()) { | |
Ok(repo) => { | |
let cfg = repo.config().unwrap(); | |
for entry in &cfg.entries(None).unwrap() { | |
let entry = entry.unwrap(); | |
println!("{} => {}", entry.name().unwrap(), entry.value().unwrap()); | |
} | |
}, | |
Err(e) => panic!("failed to init: {}", e), | |
}; | |
println!("-------"); | |
let cfg = Config::open_default().unwrap(); | |
for entry in &cfg.entries(None).unwrap() { | |
let entry = entry.unwrap(); | |
println!("{} => {}", entry.name().unwrap(), entry.value().unwrap()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment