Extract `with_git_repo_or_exit`
This function will come in handy when doing other actions with a git repo, like when modifying a repository's config.
This commit is contained in:
parent
747e19828c
commit
15886667da
12
src/lib.rs
12
src/lib.rs
|
|
@ -57,11 +57,10 @@ fn parse_coauthors_file() -> Result<BTreeMap<String, Author>, Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_gitmessage_template_path_or_exit<F: FnOnce(std::path::PathBuf)>(f: F) {
|
fn with_git_repo_or_exit<F: FnOnce(Repository)>(f: F) {
|
||||||
match Repository::open_from_env() {
|
match Repository::open_from_env() {
|
||||||
Ok(repo) => {
|
Ok(repo) => {
|
||||||
let path = repo.path().join(".gitmessage");
|
f(repo);
|
||||||
f(path);
|
|
||||||
},
|
},
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
eprintln!("Not in a git repository");
|
eprintln!("Not in a git repository");
|
||||||
|
|
@ -70,6 +69,13 @@ pub fn with_gitmessage_template_path_or_exit<F: FnOnce(std::path::PathBuf)>(f: F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_gitmessage_template_path_or_exit<F: FnOnce(std::path::PathBuf)>(f: F) {
|
||||||
|
with_git_repo_or_exit(|repo| {
|
||||||
|
let path = repo.path().join(".gitmessage");
|
||||||
|
f(path);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write_coauthors_file(authors: BTreeMap<String, Author>) {
|
pub fn write_coauthors_file(authors: BTreeMap<String, Author>) {
|
||||||
let mut wrapper_tree = BTreeMap::new();
|
let mut wrapper_tree = BTreeMap::new();
|
||||||
wrapper_tree.insert("coauthors", authors);
|
wrapper_tree.insert("coauthors", authors);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue