From 6b10269f8db7074a5f7afa703e69bc63fd3404d1 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Fri, 29 Sep 2017 15:52:21 -0700 Subject: [PATCH] Added support for aliases. Fixes #8. Supported aliases are pulled from the git-together.aliases config variable, which (if set) should be a comma-separated list of aliases e.g. "ci,rv,m". Signed-off-by: Steve Gravrock --- README.md | 10 ++++++++++ bats/integration.bats | 15 +++++++++++++++ src/lib.rs | 26 ++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e6636b..722fa01 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,16 @@ Soloing and mobbing are set by simply passing in the right number of authors to so that the author/committer roles are fairly spread across the pair/mob over time. +Aliases are supported as well. You can make git-together do its thing when you +use an alias for a committing command by configuring a comma-separated list of +aliases: + +```bash +git config git-together.aliases ci,rv,m +# ... +git ci +``` + ## Technical Details Because repo-level authors are common and there's no good way of configuring diff --git a/bats/integration.bats b/bats/integration.bats index f1ff4f3..5f0d829 100755 --- a/bats/integration.bats +++ b/bats/integration.bats @@ -210,6 +210,21 @@ AUTHORS [[ "$output" =~ "Signed-off-by: Naomi Nagata " ]] } +@test "aliases" { + git config --local git-together.aliases m,ci,r + git-together with jh nn + touch foo + git add foo + git-together ci -m "add foo" + + run git show --no-patch --format="%aN <%aE>" + [ "$output" = "James Holden " ] + run git show --no-patch --format="%cN <%cE>" + [ "$output" = "Naomi Nagata " ] + run git show --no-patch --format=%B + [[ "$output" =~ "Signed-off-by: Naomi Nagata " ]] +} + setup() { # [ -f $BATS_TMPDIR/bin/git-together ] || cargo install --root $BATS_TMPDIR rm -rf $BATS_TMPDIR/bin diff --git a/src/lib.rs b/src/lib.rs index 1f0bf1f..d5f1cdc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,15 @@ impl GitTogether { pub fn is_signoff_cmd(&self, cmd: &str) -> bool { let signoffs = ["commit", "merge", "revert"]; - signoffs.contains(&cmd) + signoffs.contains(&cmd) || self.is_signoff_alias(&cmd) + } + + fn is_signoff_alias(&self, cmd: &str) -> bool { + self.config.get(&namespaced("aliases")) + .unwrap_or("".to_string()) + .split(",") + .find(|a| *a == cmd) + .is_some() } pub fn signoff<'a>(&self, cmd: &'a mut Command) -> Result<&'a mut Command> { @@ -396,7 +404,7 @@ mod tests { } #[test] - fn is_signoff_cmd() { + fn is_signoff_cmd_basics() { let config = MockConfig::new(&[]); let author_parser = AuthorParser { domain: Some("rocinante.com".into()) }; let gt = GitTogether { @@ -410,6 +418,20 @@ mod tests { assert_eq!(gt.is_signoff_cmd("bisect"), false); } + #[test] + fn is_signoff_cmd_aliases() { + let config = MockConfig::new(&[("git-together.aliases", "ci,m,rv")]); + let author_parser = AuthorParser { domain: Some("rocinante.com".into()) }; + let gt = GitTogether { + config: config, + author_parser: author_parser, + }; + + assert_eq!(gt.is_signoff_cmd("ci"), true); + assert_eq!(gt.is_signoff_cmd("m"), true); + assert_eq!(gt.is_signoff_cmd("rv"), true); + } + struct MockConfig { data: HashMap, }