Skip to content

Commit

Permalink
git: remove ": {source}" from FailedRefExportReason, walk chain by ca…
Browse files Browse the repository at this point in the history
…ller

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.
  • Loading branch information
yuja committed Feb 4, 2024
1 parent a0cefb8 commit 1efadd9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
6 changes: 5 additions & 1 deletion cli/src/git_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions cli/tests/test_git_colocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 9 additions & 7 deletions cli/tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<gix::reference::edit::Error>),
/// 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>),
}

Expand Down

0 comments on commit 1efadd9

Please sign in to comment.