diff --git a/Cargo.lock b/Cargo.lock index c5bce68..6a5e344 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,7 +157,7 @@ dependencies = [ [[package]] name = "git_mob" -version = "0.3.2" +version = "0.3.3" dependencies = [ "dirs", "git2", diff --git a/Cargo.toml b/Cargo.toml index 120a0e4..23eddb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git_mob" -version = "0.3.2" +version = "0.3.3" authors = ["Martin Frost "] edition = "2018" description = "A CLI tool for social coding." diff --git a/README.md b/README.md index 163e3a1..71b803f 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,16 @@ It is essentially a Rust clone of the [git-mob NPM package](https://www.npmjs.co Just run `cargo install git_mob` and you should be all set. -If it does not seem to work, try to run `git config --global commit.template -.git/.gitmessage` to ensure that you have configured your your gitmessage -template to where `git-mob` is looking for it. +## A note on commit template and git-mob + +`git-mob` _will_ currently override any existing `commit.template` setting +in any project where it is run. It does this in order to ensure that `git +commit` will pick up your current mob. + +The future plan is to do something a bit smarter, like first detecting if the +repo already has a `commit.template` setting, and in that case, modify the +existing template by adding `Co-authored-by:` trailers to it, or something +similar. ## Examples diff --git a/src/bin/git-mob.rs b/src/bin/git-mob.rs index 070d6e9..aa9a39b 100644 --- a/src/bin/git-mob.rs +++ b/src/bin/git-mob.rs @@ -1,5 +1,5 @@ use git_mob::{ - get_available_coauthors, get_main_author, set_main_author, + ensure_commit_template_is_set, get_available_coauthors, get_main_author, set_main_author, with_gitmessage_template_path_or_exit, Author, }; use std::fs; @@ -31,6 +31,7 @@ fn main() { } write_coauthors_to_gitmessage_file(&opt.coauthors); + ensure_commit_template_is_set(); } fn list_coauthors() { diff --git a/src/bin/git-solo.rs b/src/bin/git-solo.rs index e2315d8..656d483 100644 --- a/src/bin/git-solo.rs +++ b/src/bin/git-solo.rs @@ -1,4 +1,6 @@ -use git_mob::{get_main_author, with_gitmessage_template_path_or_exit}; +use git_mob::{ + ensure_commit_template_is_set, get_main_author, with_gitmessage_template_path_or_exit, +}; use std::fs::File; fn main() { @@ -7,5 +9,6 @@ fn main() { with_gitmessage_template_path_or_exit(|path| { let _template = File::create(path); - }) + }); + ensure_commit_template_is_set(); } diff --git a/src/lib.rs b/src/lib.rs index 9343779..ac6206c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,15 @@ pub fn set_main_author(author: &Author) { }); } +pub fn ensure_commit_template_is_set() { + with_git_repo_or_exit(|repo| { + let mut config = repo.config().unwrap(); + config + .set_str("commit.template", &".git/.gitmessage") + .unwrap(); + }) +} + pub fn get_available_coauthors() -> BTreeMap { match parse_coauthors_file() { Ok(coauthors) => coauthors,