v0.3.3 - Ensure commit.template is set
We currently ensure this by simply overriding any existing template. This is of course sub-optimal, but the previous recommendation, to globally set `commit.template` to a relative path would otherwise make `git commit` crash when run in a repo without first creating that template file, e.g. by running `git mob ...` or `git solo` in the project directory before committing anything. This way, we don't have to globally set `commit.template`, and git-mob will still work.
This commit is contained in:
parent
20997a0605
commit
4575605991
|
|
@ -157,7 +157,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "git_mob"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"git2",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "git_mob"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
authors = ["Martin Frost <martin@frost.ws>"]
|
||||
edition = "2018"
|
||||
description = "A CLI tool for social coding."
|
||||
|
|
|
|||
13
README.md
13
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
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, Author> {
|
||||
match parse_coauthors_file() {
|
||||
Ok(coauthors) => coauthors,
|
||||
|
|
|
|||
Loading…
Reference in New Issue