Skip to content

Commit

Permalink
fix: improve error msg when adding coauthor with invalid key
Browse files Browse the repository at this point in the history
Remove suggestion to use initials for keys since first names  might be a better option for some
  • Loading branch information
Mubashwer committed Mar 29, 2024
1 parent bda1f45 commit 81fd16d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ cargo install git-mob-tool

## Configuration

- Store your team members' details with keys (usually initials)
- Store your team members' details with keys

```console
$ git mob coauthor --add lm "Leo Messi" [email protected]
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum Commands {
/// Add/delete/list co-author(s) from co-author repository
///
/// User must store co-author(s) to co-author repository by using keys
/// (usually initials) before starting pair/mob programming session(s).
/// before starting pair/mob programming session(s).
Coauthor(Coauthor),
}

Expand Down
7 changes: 4 additions & 3 deletions src/coauthor_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ impl CoauthorRepo for GitConfigCoauthorRepo {
.args(["config", "--global", &full_key, coauthor])
.output()?;

match output.status.success() {
true => Ok(()),
false => Self::git_config_error(&output),
match output.status.code() {
Some(Self::EXIT_CODE_SUCCESS) => Ok(()),
Some(Self::EXIT_CODE_CONFIG_INVALID_KEY) => Err(format!("Invalid key: {key}").into()),
_ => Self::git_config_error(&output),
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/coauthor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ fn test_add_and_list_coauthors(ctx: TestContextCli) -> Result<(), Box<dyn Error>
Ok(())
}

#[test_context(TestContextCli, skip_teardown)]
#[test]
fn test_add_coauthor_with_invalid_key(ctx: TestContextCli) -> Result<(), Box<dyn Error>> {
ctx.git()
.args([
"mob",
"coauthor",
"--add",
"invalid_key_with_underscore",
"Leo Messi",
"[email protected]",
])
.assert()
.failure()
.stderr(predicate::str::diff(
"Error: \"Invalid key: invalid_key_with_underscore\"\n",
));

Ok(())
}

#[test_context(TestContextCli, skip_teardown)]
#[test]
fn test_list_coauthors_given_no_coauthors_added(ctx: TestContextCli) -> Result<(), Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn test_coauthor_help(ctx: TestContextCli) -> Result<(), Box<dyn Error>> {
.stdout(predicate::str::diff(
r#"Add/delete/list co-author(s) from co-author repository
User must store co-author(s) to co-author repository by using keys (usually initials) before starting pair/mob programming session(s).
User must store co-author(s) to co-author repository by using keys before starting pair/mob programming session(s).
Usage: git mob coauthor [OPTIONS]
Expand Down

0 comments on commit 81fd16d

Please sign in to comment.