Skip to content

Commit

Permalink
Be more specific when warning the user about missing identity configs
Browse files Browse the repository at this point in the history
Check if only the email or the name are missing in the config and specifically name the missing one, instead of always defaulting to potentially both missing.
  • Loading branch information
Veykril committed Oct 2, 2024
1 parent f8e30fb commit 72c5bbb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
28 changes: 23 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,13 +1771,31 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \
self.report_repo_changes(ui, &old_repo)?;

let settings = self.settings();
if settings.user_name().is_empty() || settings.user_email().is_empty() {
let missing_user_name = settings.user_name().is_empty();
let missing_user_mail = settings.user_email().is_empty();
if missing_user_name || missing_user_mail {
let mut writer = ui.warning_default();
let not_configured_msg = match (missing_user_name, missing_user_mail) {
(true, true) => "Name and email not configured.",
(true, false) => "Name not configured.",
(false, true) => "Email not configured.",
_ => unreachable!(),
};
write!(writer, "{not_configured_msg} ")?;
writeln!(
ui.warning_default(),
r#"Name and email not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes. To configure, run:
jj config set --user user.name "Some One"
jj config set --user user.email "[email protected]""#
writer,
"Until configured, your commits will be created with the empty identity, and \
can't be pushed to remotes. To configure, run:",
)?;
if missing_user_name {
writeln!(writer, r#" jj config set --user user.name "Some One""#)?;
}
if missing_user_mail {
writeln!(
writer,
r#" jj config set --user user.email "[email protected]""#
)?;
}
}
Ok(())
}
Expand Down
15 changes: 13 additions & 2 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,8 @@ fn test_no_user_configured() {
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Working copy now at: qpvuntsm 7a7d6016 (empty) without name
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Warning: Name and email not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes. To configure, run:
Warning: Name not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes. To configure, run:
jj config set --user user.name "Some One"
jj config set --user user.email "[email protected]"
"###);
let assert = test_env
.jj_cmd(&repo_path, &["describe", "-m", "without email"])
Expand All @@ -580,6 +579,18 @@ fn test_no_user_configured() {
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Working copy now at: qpvuntsm 906f8b89 (empty) without email
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Warning: Email not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes. To configure, run:
jj config set --user user.email "[email protected]"
"###);
let assert = test_env
.jj_cmd(&repo_path, &["describe", "-m", "without name and email"])
.env_remove("JJ_USER")
.env_remove("JJ_EMAIL")
.assert()
.success();
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Working copy now at: qpvuntsm 57d3a489 (empty) without name and email
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Warning: Name and email not configured. Until configured, your commits will be created with the empty identity, and can't be pushed to remotes. To configure, run:
jj config set --user user.name "Some One"
jj config set --user user.email "[email protected]"
Expand Down

0 comments on commit 72c5bbb

Please sign in to comment.