forked from mirrors/jj
cli: print failed git export reason for each ref
Not all reasons are actionable, but we print hint in common cryptic cases.
This commit is contained in:
parent
990edcefc9
commit
a110ec6d95
5 changed files with 17 additions and 9 deletions
|
@ -1843,10 +1843,10 @@ pub fn print_failed_git_export(
|
||||||
if !failed_branches.is_empty() {
|
if !failed_branches.is_empty() {
|
||||||
writeln!(ui.warning(), "Failed to export some branches:")?;
|
writeln!(ui.warning(), "Failed to export some branches:")?;
|
||||||
let mut formatter = ui.stderr_formatter();
|
let mut formatter = ui.stderr_formatter();
|
||||||
for failed_ref_export in failed_branches {
|
for FailedRefExport { name, reason } in failed_branches {
|
||||||
formatter.write_str(" ")?;
|
formatter.write_str(" ")?;
|
||||||
write!(formatter.labeled("branch"), "{}", failed_ref_export.name)?;
|
write!(formatter.labeled("branch"), "{name}")?;
|
||||||
formatter.write_str("\n")?;
|
writeln!(formatter, ": {reason}")?;
|
||||||
}
|
}
|
||||||
drop(formatter);
|
drop(formatter);
|
||||||
if failed_branches
|
if failed_branches
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn test_branch_at_root() {
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Nothing changed.
|
Nothing changed.
|
||||||
Failed to export some branches:
|
Failed to export some branches:
|
||||||
fred
|
fred: Ref cannot point to the root commit in Git
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -403,7 +403,7 @@ fn test_git_colocated_conflicting_git_refs() {
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Failed to export some branches:
|
Failed to export some branches:
|
||||||
main/sub
|
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
|
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
|
another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to
|
||||||
export or their "parent" branches.
|
export or their "parent" branches.
|
||||||
|
|
|
@ -69,7 +69,7 @@ fn test_git_export_conflicting_git_refs() {
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Failed to export some branches:
|
Failed to export some branches:
|
||||||
main/sub
|
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
|
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
|
another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to
|
||||||
export or their "parent" branches.
|
export or their "parent" branches.
|
||||||
|
|
|
@ -543,25 +543,33 @@ pub struct FailedRefExport {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The reason we failed to export a ref to Git.
|
/// The reason we failed to export a ref to Git.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub enum FailedRefExportReason {
|
pub enum FailedRefExportReason {
|
||||||
/// The name is not allowed in Git.
|
/// The name is not allowed in Git.
|
||||||
|
#[error("Name is not allowed in Git")]
|
||||||
InvalidGitName,
|
InvalidGitName,
|
||||||
/// The ref was in a conflicted state from the last import. A re-import
|
/// The ref was in a conflicted state from the last import. A re-import
|
||||||
/// should fix it.
|
/// should fix it.
|
||||||
|
#[error("Ref was in a conflicted state from the last import")]
|
||||||
ConflictedOldState,
|
ConflictedOldState,
|
||||||
/// The branch points to the root commit, which Git doesn't have
|
/// The branch points to the root commit, which Git doesn't have
|
||||||
|
#[error("Ref cannot point to the root commit in Git")]
|
||||||
OnRootCommit,
|
OnRootCommit,
|
||||||
/// We wanted to delete it, but it had been modified in Git.
|
/// We wanted to delete it, but it had been modified in Git.
|
||||||
|
#[error("Deleted ref had been modified in Git")]
|
||||||
DeletedInJjModifiedInGit,
|
DeletedInJjModifiedInGit,
|
||||||
/// We wanted to add it, but Git had added it with a different target
|
/// We wanted to add it, but Git had added it with a different target
|
||||||
|
#[error("Added ref had been added with a different target in Git")]
|
||||||
AddedInJjAddedInGit,
|
AddedInJjAddedInGit,
|
||||||
/// We wanted to modify it, but Git had deleted it
|
/// We wanted to modify it, but Git had deleted it
|
||||||
|
#[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
|
||||||
FailedToDelete(Box<gix::reference::edit::Error>),
|
#[error("Failed to delete: {0}")]
|
||||||
|
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
|
||||||
FailedToSet(Box<gix::reference::edit::Error>),
|
#[error("Failed to set: {0}")]
|
||||||
|
FailedToSet(#[source] Box<gix::reference::edit::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Reference in a new issue