Skip to content

Commit

Permalink
Added support for aliases. Fixes #8.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sgravrock authored and kejadlen committed Sep 30, 2017
1 parent f819803 commit 6b10269
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions bats/integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ AUTHORS
[[ "$output" =~ "Signed-off-by: Naomi Nagata <[email protected]>" ]]
}

@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 <[email protected]>" ]
run git show --no-patch --format="%cN <%cE>"
[ "$output" = "Naomi Nagata <[email protected]>" ]
run git show --no-patch --format=%B
[[ "$output" =~ "Signed-off-by: Naomi Nagata <[email protected]>" ]]
}

setup() {
# [ -f $BATS_TMPDIR/bin/git-together ] || cargo install --root $BATS_TMPDIR
rm -rf $BATS_TMPDIR/bin
Expand Down
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ impl<C: config::Config> GitTogether<C> {

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> {
Expand Down Expand Up @@ -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 {
Expand All @@ -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<String, String>,
}
Expand Down

0 comments on commit 6b10269

Please sign in to comment.