diff --git a/src/bin/git-mob.rs b/src/bin/git-mob.rs index ff7c471..5b6019d 100644 --- a/src/bin/git-mob.rs +++ b/src/bin/git-mob.rs @@ -1,5 +1,4 @@ -use git_mob::{Author, get_main_author, get_available_coauthors, gitmessage_template_file_path, with_repo_or_exit}; -use git2::Repository; +use git_mob::{Author, get_main_author, get_available_coauthors, with_gitmessage_template_path_or_exit}; use structopt::StructOpt; use std::process; use std::fs; @@ -37,9 +36,7 @@ fn write_coauthors_to_gitmessage_file(coauthor_initials: &[String]) { content.push_str(&format!("Co-authored-by: {}\n", &author.to_string())); } - with_repo_or_exit(|repo: Repository| { - let path = gitmessage_template_file_path(repo); - + with_gitmessage_template_path_or_exit(|path| { match fs::write(path, content) { Ok(_) => { println!("{}", get_main_author()); diff --git a/src/bin/git-solo.rs b/src/bin/git-solo.rs index 4edc6b4..2f4b318 100644 --- a/src/bin/git-solo.rs +++ b/src/bin/git-solo.rs @@ -1,13 +1,11 @@ -use git2::Repository; use std::fs::File; -use git_mob::{get_main_author, gitmessage_template_file_path, with_repo_or_exit}; +use git_mob::{get_main_author, with_gitmessage_template_path_or_exit}; fn main() { let main_author = get_main_author(); println!("{}", main_author); - with_repo_or_exit(|repo: Repository| { - let path = gitmessage_template_file_path(repo); + with_gitmessage_template_path_or_exit(|path| { let _template = File::create(path); }) } diff --git a/src/lib.rs b/src/lib.rs index 19e6426..4af5f4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,13 +57,12 @@ fn parse_coauthors_file() -> Result, Box> { } } -pub fn gitmessage_template_file_path(repo: Repository) -> std::path::PathBuf { - repo.path().join(".gitmessage") -} - -pub fn with_repo_or_exit(f: F) { +pub fn with_gitmessage_template_path_or_exit(f: F) { match Repository::open_from_env() { - Ok(repo) => f(repo), + Ok(repo) => { + let path = repo.path().join(".gitmessage"); + f(path); + }, Err(_e) => { eprintln!("Not in a git repository"); process::exit(1);