Skip to content

Commit

Permalink
Mention --allow-large-revsets in hint when one revset resolves to mul…
Browse files Browse the repository at this point in the history
…tiple revisions
  • Loading branch information
ilyagr committed Feb 6, 2023
1 parent 91e9490 commit 0cf5279
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,9 @@ pub fn resolve_mutliple_nonempty_revsets_flag_guarded(
} else {
let mut commits = IndexSet::new();
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(append_large_revsets_hint_if_mutltiple_revisions)?;
let commit_hash = short_commit_hash(commit.id());
if !commits.insert(commit) {
return Err(user_error(format!(
Expand All @@ -1431,6 +1433,24 @@ pub fn resolve_mutliple_nonempty_revsets_flag_guarded(
}
}

fn append_large_revsets_hint_if_mutltiple_revisions(err: CommandError) -> CommandError {
match err {
CommandError::UserError { message, hint } if message.contains("more than one revision") => {
CommandError::UserError {
message,
hint: {
Some(format!(
"{old_hint}If this was intentional, specify the `--allow-large-revsets` \
argument",
old_hint = hint.map(|h| format!("{h}\n")).unwrap_or_default()
))
},
}
}
_ => 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 `--allow-large-revsets` argument
"###);
let stdout = test_env.jj_cmd_success(
&repo_path,
Expand Down

0 comments on commit 0cf5279

Please sign in to comment.