From 41908686ed0c80d5d18f203329968580939fe34f Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Fri, 22 May 2020 22:21:41 +0200 Subject: [PATCH] Extract gitmessage_template_file_path to lib This piece of code will be used in a variety of places, so let's put it somewhere where we can easily share it. --- src/bin/git-solo.rs | 6 +++--- src/lib.rs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/git-solo.rs b/src/bin/git-solo.rs index f3a5428..9abccd6 100644 --- a/src/bin/git-solo.rs +++ b/src/bin/git-solo.rs @@ -1,7 +1,7 @@ use git2::Repository; use std::process; use std::fs::File; -use git_mob::get_main_author; +use git_mob::{get_main_author, gitmessage_template_file_path}; fn main() { let main_author = get_main_author(); @@ -19,6 +19,6 @@ fn main() { } fn truncate_gitmessage_template(repo: Repository) { - let template_path = repo.path().join(".gitmessage"); - let _template = File::create(template_path); + let path = gitmessage_template_file_path(repo); + let _template = File::create(path); } diff --git a/src/lib.rs b/src/lib.rs index bf61c2c..e55602e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use git2::Config; +use git2::{Config, Repository}; use std::fmt; use std::collections::BTreeMap; use dirs::home_dir; @@ -54,3 +54,7 @@ fn parse_coauthors_file() -> Result, Box> { None => Ok(BTreeMap::new()) } } + +pub fn gitmessage_template_file_path(repo: Repository) -> std::path::PathBuf { + repo.path().join(".gitmessage") +}