diff --git a/cli/src/git_util.rs b/cli/src/git_util.rs index 04f2d86ea..81f756f34 100644 --- a/cli/src/git_util.rs +++ b/cli/src/git_util.rs @@ -19,6 +19,7 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use std::sync::Mutex; use std::time::Instant; +use std::{error, iter}; use jj_lib::git::{self, FailedRefExport, FailedRefExportReason, GitImportStats}; use jj_lib::git_backend::GitBackend; @@ -172,7 +173,10 @@ pub fn print_failed_git_export( for FailedRefExport { name, reason } in failed_branches { formatter.write_str(" ")?; write!(formatter.labeled("branch"), "{name}")?; - writeln!(formatter, ": {reason}")?; + for err in iter::successors(Some(reason as &dyn error::Error), |err| err.source()) { + write!(formatter, ": {err}")?; + } + writeln!(formatter)?; } drop(formatter); if failed_branches diff --git a/cli/tests/test_git_colocated.rs b/cli/tests/test_git_colocated.rs index 1a9867653..7a1a9e8d9 100644 --- a/cli/tests/test_git_colocated.rs +++ b/cli/tests/test_git_colocated.rs @@ -402,13 +402,15 @@ fn test_git_colocated_conflicting_git_refs() { test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main"]); let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main/sub"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Failed to export some branches: - main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub" - Hint: Git doesn't allow a branch name that looks like a parent directory of - another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to - export or their "parent" branches. - "###); + insta::with_settings!({filters => vec![(": The lock for resource.*", ": ...")]}, { + insta::assert_snapshot!(stderr, @r###" + Failed to export some branches: + main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub": ... + Hint: Git doesn't allow a branch name that looks like a parent directory of + another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to + export or their "parent" branches. + "###); + }); } #[test] diff --git a/cli/tests/test_git_import_export.rs b/cli/tests/test_git_import_export.rs index fc537d14f..b64c275eb 100644 --- a/cli/tests/test_git_import_export.rs +++ b/cli/tests/test_git_import_export.rs @@ -67,13 +67,15 @@ fn test_git_export_conflicting_git_refs() { test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main/sub"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Failed to export some branches: - main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub" - Hint: Git doesn't allow a branch name that looks like a parent directory of - another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to - export or their "parent" branches. - "###); + insta::with_settings!({filters => vec![(": The lock for resource.*", ": ...")]}, { + insta::assert_snapshot!(stderr, @r###" + Failed to export some branches: + main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub": ... + Hint: Git doesn't allow a branch name that looks like a parent directory of + another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to + export or their "parent" branches. + "###); + }); } #[test] diff --git a/lib/src/git.rs b/lib/src/git.rs index 9ba01bf4f..fc02536ca 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -592,10 +592,10 @@ pub enum FailedRefExportReason { #[error("Modified ref had been deleted in Git")] ModifiedInJjDeletedInGit, /// Failed to delete the ref from the Git repo - #[error("Failed to delete: {0}")] + #[error("Failed to delete")] FailedToDelete(#[source] Box), /// Failed to set the ref in the Git repo - #[error("Failed to set: {0}")] + #[error("Failed to set")] FailedToSet(#[source] Box), }