Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more specific when warning the user about missing identity configs #4429

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,13 +1613,31 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \
}

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:",
PhilipMetzger marked this conversation as resolved.
Show resolved Hide resolved
)?;
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