From 15886667da1330df11f2ac1dc6cd7ddec6951624 Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Fri, 19 Jun 2020 13:23:56 +0200 Subject: [PATCH] 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. --- src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4af5f4f..46f31ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,11 +57,10 @@ fn parse_coauthors_file() -> Result, Box> { } } -pub fn with_gitmessage_template_path_or_exit(f: F) { +fn with_git_repo_or_exit(f: F) { match Repository::open_from_env() { Ok(repo) => { - let path = repo.path().join(".gitmessage"); - f(path); + f(repo); }, Err(_e) => { eprintln!("Not in a git repository"); @@ -70,6 +69,13 @@ pub fn with_gitmessage_template_path_or_exit(f: F } } +pub fn with_gitmessage_template_path_or_exit(f: F) { + with_git_repo_or_exit(|repo| { + let path = repo.path().join(".gitmessage"); + f(path); + }) +} + pub fn write_coauthors_file(authors: BTreeMap) { let mut wrapper_tree = BTreeMap::new(); wrapper_tree.insert("coauthors", authors);