cli: use placeholder name/email if not configured instead of crashing

This commit is contained in:
Martin von Zweigbergk 2021-05-16 13:45:08 -07:00
parent b97d25038b
commit 31f3984728
2 changed files with 9 additions and 3 deletions

View File

@ -55,13 +55,15 @@ impl UserSettings {
} }
pub fn user_name(&self) -> String { pub fn user_name(&self) -> String {
self.config.get_str("user.name").expect("no user.name set") self.config
.get_str("user.name")
.unwrap_or_else(|_| "<no name configured>".to_string())
} }
pub fn user_email(&self) -> String { pub fn user_email(&self) -> String {
self.config self.config
.get_str("user.email") .get_str("user.email")
.expect("no user.email set") .unwrap_or_else(|_| "<no email configured>".to_string())
} }
pub fn config(&self) -> &config::Config { pub fn config(&self) -> &config::Config {

View File

@ -825,7 +825,11 @@ fn cmd_files(
let mut repo_command = command.repo_helper(ui)?; let mut repo_command = command.repo_helper(ui)?;
let commit = repo_command.resolve_revision_arg(sub_matches)?; let commit = repo_command.resolve_revision_arg(sub_matches)?;
for (name, _value) in commit.tree().entries() { for (name, _value) in commit.tree().entries() {
writeln!(ui, "{}", &ui.format_file_path(repo_command.repo().working_copy_path(), &name))?; writeln!(
ui,
"{}",
&ui.format_file_path(repo_command.repo().working_copy_path(), &name)
)?;
} }
Ok(()) Ok(())
} }