Skip to content

Instantly share code, notes, and snippets.

@PurpleBooth

PurpleBooth/demo.rs

Created Apr 19, 2020
Embed
What would you like to do?
Reading git config from global and the containing repo in rust
#!/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