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

git: remove ": {source}" from FailedRefExportReason, walk chain by caller

The error output gets more verbose because all gix error sources are printed.
Maybe we'll need a better formatting, but changing to multi-line output doesn't
look nice either.
This commit is contained in:
Yuya Nishihara 2024-02-03 17:17:05 +09:00
parent a0cefb8b7b
commit 1efadd96c8
4 changed files with 25 additions and 17 deletions

View file

@ -19,6 +19,7 @@ use std::path::{Path, PathBuf};
use std::process::Stdio; use std::process::Stdio;
use std::sync::Mutex; use std::sync::Mutex;
use std::time::Instant; use std::time::Instant;
use std::{error, iter};
use jj_lib::git::{self, FailedRefExport, FailedRefExportReason, GitImportStats}; use jj_lib::git::{self, FailedRefExport, FailedRefExportReason, GitImportStats};
use jj_lib::git_backend::GitBackend; use jj_lib::git_backend::GitBackend;
@ -172,7 +173,10 @@ pub fn print_failed_git_export(
for FailedRefExport { name, reason } in failed_branches { for FailedRefExport { name, reason } in failed_branches {
formatter.write_str(" ")?; formatter.write_str(" ")?;
write!(formatter.labeled("branch"), "{name}")?; 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); drop(formatter);
if failed_branches if failed_branches

View file

@ -402,13 +402,15 @@ fn test_git_colocated_conflicting_git_refs() {
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main"]); test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main/sub"]); let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main/sub"]);
insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###" insta::with_settings!({filters => vec![(": The lock for resource.*", ": ...")]}, {
Failed to export some branches: insta::assert_snapshot!(stderr, @r###"
main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub" Failed to export some branches:
Hint: Git doesn't allow a branch name that looks like a parent directory of main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub": ...
another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to Hint: Git doesn't allow a branch name that looks like a parent directory of
export or their "parent" branches. another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to
"###); export or their "parent" branches.
"###);
});
} }
#[test] #[test]

View file

@ -67,13 +67,15 @@ fn test_git_export_conflicting_git_refs() {
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main/sub"]); test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main/sub"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###" insta::with_settings!({filters => vec![(": The lock for resource.*", ": ...")]}, {
Failed to export some branches: insta::assert_snapshot!(stderr, @r###"
main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub" Failed to export some branches:
Hint: Git doesn't allow a branch name that looks like a parent directory of main/sub: Failed to set: A lock could not be obtained for reference "refs/heads/main/sub": ...
another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to Hint: Git doesn't allow a branch name that looks like a parent directory of
export or their "parent" branches. another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to
"###); export or their "parent" branches.
"###);
});
} }
#[test] #[test]

View file

@ -592,10 +592,10 @@ pub enum FailedRefExportReason {
#[error("Modified ref had been deleted in Git")] #[error("Modified ref had been deleted in Git")]
ModifiedInJjDeletedInGit, ModifiedInJjDeletedInGit,
/// Failed to delete the ref from the Git repo /// Failed to delete the ref from the Git repo
#[error("Failed to delete: {0}")] #[error("Failed to delete")]
FailedToDelete(#[source] Box<gix::reference::edit::Error>), FailedToDelete(#[source] Box<gix::reference::edit::Error>),
/// Failed to set the ref in the Git repo /// Failed to set the ref in the Git repo
#[error("Failed to set: {0}")] #[error("Failed to set")]
FailedToSet(#[source] Box<gix::reference::edit::Error>), FailedToSet(#[source] Box<gix::reference::edit::Error>),
} }