ok/jj
1
0
Fork 0
forked from mirrors/jj

Be more specific when warning the user about missing identity configs

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.
This commit is contained in:
Lukas Wirth 2024-09-10 16:16:16 +02:00
parent f8e30fb1de
commit 72c5bbb4e6
2 changed files with 36 additions and 7 deletions

View file

@ -1771,13 +1771,31 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \
self.report_repo_changes(ui, &old_repo)?; self.report_repo_changes(ui, &old_repo)?;
let settings = self.settings(); 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!( writeln!(
ui.warning_default(), writer,
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: "Until configured, your commits will be created with the empty identity, and \
jj config set --user user.name "Some One" can't be pushed to remotes. To configure, run:",
jj config set --user user.email "someone@example.com""#
)?; )?;
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 "someone@example.com""#
)?;
}
} }
Ok(()) Ok(())
} }

View file

@ -568,9 +568,8 @@ fn test_no_user_configured() {
insta::assert_snapshot!(get_stderr_string(&assert), @r###" insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Working copy now at: qpvuntsm 7a7d6016 (empty) without name Working copy now at: qpvuntsm 7a7d6016 (empty) without name
Parent commit : zzzzzzzz 00000000 (empty) (no description set) 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.name "Some One"
jj config set --user user.email "someone@example.com"
"###); "###);
let assert = test_env let assert = test_env
.jj_cmd(&repo_path, &["describe", "-m", "without email"]) .jj_cmd(&repo_path, &["describe", "-m", "without email"])
@ -580,6 +579,18 @@ fn test_no_user_configured() {
insta::assert_snapshot!(get_stderr_string(&assert), @r###" insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Working copy now at: qpvuntsm 906f8b89 (empty) without email Working copy now at: qpvuntsm 906f8b89 (empty) without email
Parent commit : zzzzzzzz 00000000 (empty) (no description set) 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 "someone@example.com"
"###);
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: 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.name "Some One"
jj config set --user user.email "someone@example.com" jj config set --user user.email "someone@example.com"