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.
This commit is contained in:
Martin Frost 2020-05-22 22:21:41 +02:00
parent de5af01d1f
commit 41908686ed
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,7 @@
use git2::Repository; use git2::Repository;
use std::process; use std::process;
use std::fs::File; use std::fs::File;
use git_mob::get_main_author; use git_mob::{get_main_author, gitmessage_template_file_path};
fn main() { fn main() {
let main_author = get_main_author(); let main_author = get_main_author();
@ -19,6 +19,6 @@ fn main() {
} }
fn truncate_gitmessage_template(repo: Repository) { fn truncate_gitmessage_template(repo: Repository) {
let template_path = repo.path().join(".gitmessage"); let path = gitmessage_template_file_path(repo);
let _template = File::create(template_path); let _template = File::create(path);
} }

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use git2::Config; use git2::{Config, Repository};
use std::fmt; use std::fmt;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use dirs::home_dir; use dirs::home_dir;
@ -54,3 +54,7 @@ fn parse_coauthors_file() -> Result<BTreeMap<String, Author>, Box<dyn Error>> {
None => Ok(BTreeMap::new()) None => Ok(BTreeMap::new())
} }
} }
pub fn gitmessage_template_file_path(repo: Repository) -> std::path::PathBuf {
repo.path().join(".gitmessage")
}