Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mention --multi in hint when one revset resolves to multiple revisions
Browse files Browse the repository at this point in the history
ilyagr committed Feb 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ba30263 commit e58ad87
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/cli_util.rs
Original file line number Diff line number Diff line change
@@ -1397,9 +1397,10 @@ pub fn resolve_base_revs(
commits.extend(revisions);
}
} else {
// TODO: Change the error resolve_single_rev returns!
for revision_str in revisions {
let commit = workspace_command.resolve_single_rev(revision_str)?;
let commit = workspace_command
.resolve_single_rev(revision_str)
.map_err(add_multi_message_to_hint_if_mutliple_revisions)?;
let commit_hash = short_commit_hash(commit.id());
if !commits.insert(commit) {
return Err(user_error(format!(
@@ -1417,6 +1418,22 @@ pub fn resolve_base_revs(
}
}

fn add_multi_message_to_hint_if_mutliple_revisions(err: CommandError) -> CommandError {
if let CommandError::UserError { message, hint } = err {
let hint = if message.contains("more than one revision") {
let hint = hint.map(|h| format!("{h}\n")).unwrap_or_default();
Some(format!(
"{hint}If this was intentional, specify the `--multi` argument"
))
} else {
hint
};
CommandError::UserError { message, hint }
} else {
err
}
}

pub fn update_working_copy(
ui: &mut Ui,
repo: &Arc<ReadonlyRepo>,
1 change: 1 addition & 0 deletions tests/test_rebase_command.rs
Original file line number Diff line number Diff line change
@@ -320,6 +320,7 @@ fn test_rebase_multiple_destinations() {
Hint: The revset "b|c" resolved to these revisions:
fe2e8e8b50b3 c
d370aee184ba b
If this was intentional, specify the `--multi` argument
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["rebase", "--multi", "-r", "a", "-d", "b|c"]);

0 comments on commit e58ad87

Please sign in to comment.