Skip to content

Commit

Permalink
Mention --multi in hint when one revset resolves to multiple revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Feb 4, 2023
1 parent 8f632bf commit 33a8bd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,9 @@ pub fn resolve_base_revs(
}
} else {
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!(
Expand All @@ -1416,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>,
Expand Down
1 change: 1 addition & 0 deletions tests/test_rebase_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down

0 comments on commit 33a8bd6

Please sign in to comment.