From 429cdb38d7731b9bfd84d2d38a00567bec40f150 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 16 Mar 2024 11:57:33 +0900 Subject: [PATCH] cli: don't bury GitImportError sources #3301 --- cli/src/command_error.rs | 6 ++++-- cli/tests/test_git_fetch.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 8fa0af42b..9e6ed9e57 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -303,7 +303,6 @@ impl From for CommandError { impl From for CommandError { fn from(err: GitImportError) -> Self { - let message = format!("Failed to import refs from underlying Git repo: {err}"); let hint = match &err { GitImportError::MissingHeadTarget { .. } | GitImportError::MissingRefAncestor { .. } => Some( @@ -323,7 +322,10 @@ repository contents." GitImportError::InternalGitError(_) => None, GitImportError::UnexpectedBackend => None, }; - user_error_with_hint_opt(message, hint) + user_error_with_hint_opt( + ErrorWithMessage::new("Failed to import refs from underlying Git repo", err), + hint, + ) } } diff --git a/cli/tests/test_git_fetch.rs b/cli/tests/test_git_fetch.rs index 034d998b1..66a276be7 100644 --- a/cli/tests/test_git_fetch.rs +++ b/cli/tests/test_git_fetch.rs @@ -276,7 +276,8 @@ fn test_git_fetch_from_remote_named_git() { // Try fetching from the remote named 'git'. let stderr = &test_env.jj_cmd_failure(&repo_path, &["git", "fetch", "--remote=git"]); insta::assert_snapshot!(stderr, @r###" - Error: Failed to import refs from underlying Git repo: Git remote named 'git' is reserved for local Git repository + Error: Failed to import refs from underlying Git repo + Caused by: Git remote named 'git' is reserved for local Git repository Hint: Run `jj git remote rename` to give different name. "###); @@ -288,7 +289,8 @@ fn test_git_fetch_from_remote_named_git() { // Explicit import is an error. // (This could be warning if we add mechanism to report ignored refs.) insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["git", "import"]), @r###" - Error: Failed to import refs from underlying Git repo: Git remote named 'git' is reserved for local Git repository + Error: Failed to import refs from underlying Git repo + Caused by: Git remote named 'git' is reserved for local Git repository Hint: Run `jj git remote rename` to give different name. "###);