From 9014666d6a3bafe7287d0f5978fd3ecbf421594b Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Thu, 29 Jun 2017 08:05:14 -0700 Subject: [PATCH] Add `together` as a trigger Fixes #19 --- bats/integration.bats | 14 ++++++++++++++ src/lib.rs | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/bats/integration.bats b/bats/integration.bats index 1170ce8..f1ff4f3 100755 --- a/bats/integration.bats +++ b/bats/integration.bats @@ -196,6 +196,20 @@ AUTHORS [ "$output" = "" ] } +@test "together" { + git-together together jh nn + touch foo + git add foo + git-together commit -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 692fbf1..a1b77af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,8 +28,10 @@ pub fn run() -> Result<()> { let all_args: Vec<_> = env::args().skip(1).collect(); let args: Vec<&str> = all_args.iter().map(String::as_ref).collect(); + let triggers = ["with", "together"]; + let signoffs = ["commit", "merge", "revert"]; match *args.as_slice() { - ["with"] => { + [sub_cmd] if triggers.contains(&sub_cmd) => { let gt = GitTogether::new()?; let inits = gt.get_active()?; @@ -40,7 +42,7 @@ pub fn run() -> Result<()> { println!("{}: {}", initials, author); } } - ["with", "--list"] => { + [sub_cmd, "--list"] if triggers.contains(&sub_cmd) => { let gt = GitTogether::new()?; let authors = gt.all_authors()?; @@ -51,17 +53,17 @@ pub fn run() -> Result<()> { println!("{}: {}", initials, author); } } - ["with", "--clear"] => { + [sub_cmd, "--clear"] if triggers.contains(&sub_cmd) => { let mut gt = GitTogether::new()?; let _ = gt.set_active(&[]); } - ["with", "--version"] => { + [sub_cmd, "--version"] if triggers.contains(&sub_cmd) => { println!("{} {}", option_env!("CARGO_PKG_NAME").unwrap_or("git-together"), option_env!("CARGO_PKG_VERSION").unwrap_or("unknown version")); } - ["with", ref inits..] => { + [sub_cmd, ref inits..] if triggers.contains(&sub_cmd) => { let mut gt = GitTogether::new()?; let authors = gt.set_active(inits)?; @@ -69,7 +71,7 @@ pub fn run() -> Result<()> { println!("{}", author); } } - [sub_cmd, ref rest..] if ["commit", "merge", "revert"].contains(&sub_cmd) => { + [sub_cmd, ref rest..] if signoffs.contains(&sub_cmd) => { let mut gt = GitTogether::new()?; if sub_cmd == "merge" {