diff --git a/Cargo.toml b/Cargo.toml index df463f0..eb900eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git_mob" -version = "0.2.0" +version = "0.3.0" authors = ["Martin Frost "] edition = "2018" description = "A CLI tool for social coding." diff --git a/README.md b/README.md index 43870ce..7144334 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,11 @@ Just run `cargo install git_mob` and you should be all set. ## Examples -* Add Alice and Bob as a possible co-authors: +* Add Alice, Bob, and yourself as a possible co-authors: git add-coauthor a "Alice" alice@example.com git add-coauthor b "bob" Bob@example.com + git add-coauthor me "me" myself.i@example.com * Set Alice as co-author, making your mob consist of you and Alice: @@ -28,6 +29,10 @@ Just run `cargo install git_mob` and you should be all set. git mob a b +* Set Alice as the main author for any commits you make, since she is the one doing most of the thinking anyway, and add yourself as a mob member: + + git mob -o a b me + * Edit Bob's name, since you accidentally capitalized his email instead of his name: git edit-coauthor b --name "Bob" --email bob@example.com @@ -49,6 +54,7 @@ Just run `cargo install git_mob` and you should be all set. * `git mob ` * `git add-coauthor "Co-author Name" ` +* `git -o ` for overwriting the main author * `git edit-coauthor [--name "Co-author Name"] [--email ]` * `git delete-coauthor ` * `git mob -l` @@ -65,7 +71,6 @@ be implemented, and then there is also a severe lack of tests and documentation. * `git mob-print` * `git suggest-coauthors` -* `-o` for overwriting the main author * `--installTemplate` and `--uninstallTemplate` for prepare-commit-msg diff --git a/src/bin/git-mob.rs b/src/bin/git-mob.rs index 5b6019d..2122eb2 100644 --- a/src/bin/git-mob.rs +++ b/src/bin/git-mob.rs @@ -1,4 +1,4 @@ -use git_mob::{Author, get_main_author, get_available_coauthors, with_gitmessage_template_path_or_exit}; +use git_mob::{Author, get_main_author, get_available_coauthors, with_gitmessage_template_path_or_exit, set_main_author}; use structopt::StructOpt; use std::process; use std::fs; @@ -8,6 +8,9 @@ struct Opt { /// Prints list of available co-authors #[structopt(short,long)] list: bool, + /// Overwrite the main author + #[structopt(short,long)] + overwrite: Option, /// A list of co-author initials coauthors: Vec, } @@ -20,6 +23,10 @@ fn main() { process::exit(0); } + if let Some(initials) = opt.overwrite { + override_main_author(&initials); + } + write_coauthors_to_gitmessage_file(&opt.coauthors); } @@ -29,6 +36,17 @@ fn list_coauthors() { } } +fn override_main_author(initials: &String) { + let all_authors = get_available_coauthors(); + match all_authors.get(initials) { + Some(new_main_author) => set_main_author(&new_main_author), + None => { + eprintln!("Error: author with initials {} not found", initials); + process::exit(1); + } + } +} + fn write_coauthors_to_gitmessage_file(coauthor_initials: &[String]) { let coauthors = select_coauthors(&coauthor_initials); let mut content = String::from("\n\n"); diff --git a/src/lib.rs b/src/lib.rs index 46f31ef..bfeecb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,14 @@ pub fn get_main_author() -> Author { } } +pub fn set_main_author(author: &Author) { + with_git_repo_or_exit(|repo| { + let mut config = repo.config().unwrap(); + config.set_str("user.name", &author.name).unwrap(); + config.set_str("user.email", &author.email).unwrap(); + }); +} + pub fn get_available_coauthors() -> BTreeMap { match parse_coauthors_file() { Ok(coauthors) => coauthors,