mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
cli: duplicate: parse -rREV option properly
Since "jj duplicate" interface is now quite similar to "jj rebase", it's annoying that "-r" isn't parsed properly.
This commit is contained in:
parent
a9d4886997
commit
b0c7d0a7e2
3 changed files with 19 additions and 14 deletions
|
@ -51,12 +51,11 @@ use crate::ui::Ui;
|
||||||
/// specified commits.
|
/// specified commits.
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
pub(crate) struct DuplicateArgs {
|
pub(crate) struct DuplicateArgs {
|
||||||
/// The revision(s) to duplicate
|
/// The revision(s) to duplicate (default: @)
|
||||||
#[arg(default_value = "@", add = ArgValueCandidates::new(complete::all_revisions))]
|
#[arg(value_name = "REVISIONS", add = ArgValueCandidates::new(complete::all_revisions))]
|
||||||
revisions: Vec<RevisionArg>,
|
revisions_pos: Vec<RevisionArg>,
|
||||||
/// Ignored (but lets you pass `-r` for consistency with other commands)
|
#[arg(short = 'r', hide = true)]
|
||||||
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
|
revisions_opt: Vec<RevisionArg>,
|
||||||
unused_revision: u8,
|
|
||||||
/// The revision(s) to duplicate onto (can be repeated to create a merge
|
/// The revision(s) to duplicate onto (can be repeated to create a merge
|
||||||
/// commit)
|
/// commit)
|
||||||
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
|
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
|
||||||
|
@ -90,8 +89,13 @@ pub(crate) fn cmd_duplicate(
|
||||||
args: &DuplicateArgs,
|
args: &DuplicateArgs,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut workspace_command = command.workspace_helper(ui)?;
|
let mut workspace_command = command.workspace_helper(ui)?;
|
||||||
let to_duplicate: Vec<CommitId> = workspace_command
|
let to_duplicate: Vec<CommitId> =
|
||||||
.parse_union_revsets(ui, &args.revisions)?
|
if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() {
|
||||||
|
workspace_command
|
||||||
|
.parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())?
|
||||||
|
} else {
|
||||||
|
workspace_command.parse_revset(ui, &RevisionArg::AT)?
|
||||||
|
}
|
||||||
.evaluate_to_commit_ids()?
|
.evaluate_to_commit_ids()?
|
||||||
.try_collect()?; // in reverse topological order
|
.try_collect()?; // in reverse topological order
|
||||||
if to_duplicate.is_empty() {
|
if to_duplicate.is_empty() {
|
||||||
|
|
|
@ -755,9 +755,7 @@ When any of the `--destination`, `--insert-after`, or `--insert-before` argument
|
||||||
|
|
||||||
###### **Arguments:**
|
###### **Arguments:**
|
||||||
|
|
||||||
* `<REVISIONS>` — The revision(s) to duplicate
|
* `<REVISIONS>` — The revision(s) to duplicate (default: @)
|
||||||
|
|
||||||
Default value: `@`
|
|
||||||
|
|
||||||
###### **Options:**
|
###### **Options:**
|
||||||
|
|
||||||
|
|
|
@ -344,7 +344,8 @@ fn test_duplicate_destination() {
|
||||||
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]);
|
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]);
|
||||||
// Duplicate multiple commits without a direct ancestry relationship onto a
|
// Duplicate multiple commits without a direct ancestry relationship onto a
|
||||||
// single destination.
|
// single destination.
|
||||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a1", "b", "-d", "c"]);
|
let (stdout, stderr) =
|
||||||
|
test_env.jj_cmd_ok(&repo_path, &["duplicate", "-r=a1", "-r=b", "-d", "c"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
insta::assert_snapshot!(stderr, @r"
|
insta::assert_snapshot!(stderr, @r"
|
||||||
Duplicated 9e85a474f005 as xlzxqlsl da0996fd a1
|
Duplicated 9e85a474f005 as xlzxqlsl da0996fd a1
|
||||||
|
@ -369,8 +370,10 @@ fn test_duplicate_destination() {
|
||||||
|
|
||||||
// Duplicate multiple commits without a direct ancestry relationship onto
|
// Duplicate multiple commits without a direct ancestry relationship onto
|
||||||
// multiple destinations.
|
// multiple destinations.
|
||||||
let (stdout, stderr) =
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
||||||
test_env.jj_cmd_ok(&repo_path, &["duplicate", "a1", "b", "-d", "c", "-d", "d"]);
|
&repo_path,
|
||||||
|
&["duplicate", "-r=a1", "b", "-d", "c", "-d", "d"],
|
||||||
|
);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
insta::assert_snapshot!(stderr, @r"
|
insta::assert_snapshot!(stderr, @r"
|
||||||
Duplicated 9e85a474f005 as oupztwtk 2f519daa a1
|
Duplicated 9e85a474f005 as oupztwtk 2f519daa a1
|
||||||
|
|
Loading…
Reference in a new issue