Skip to content

Commit

Permalink
cli: duplicate: deprecate positional revisions argument
Browse files Browse the repository at this point in the history
Since the interface is now quite similar to "jj rebase", I think it's better to
require "-r". We might want to add "--source"/"--branch" later.
  • Loading branch information
yuja committed Dec 5, 2024
1 parent 32d2a85 commit a2eea49
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 92 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Deprecations

* `jj duplicate REV` is deprecated in favor of `-r REV`.

### New features

### Fixed bugs
Expand Down
17 changes: 12 additions & 5 deletions cli/src/commands/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct DuplicateArgs {
/// The revision(s) to duplicate (default: @)
#[arg(value_name = "REVISIONS", add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(short = 'r', long, add = ArgValueCandidates::new(complete::all_revisions))]
revisions: Vec<RevisionArg>,
// TODO: Delete revisions_pos in jj 0.30+
#[arg(hide = true, value_name = "REVISIONS")]
revisions_pos: Vec<RevisionArg>,
#[arg(short = 'r', hide = true)]
revisions_opt: Vec<RevisionArg>,
/// The revision(s) to duplicate onto (can be repeated to create a merge
/// commit)
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
Expand Down Expand Up @@ -89,10 +90,16 @@ pub(crate) fn cmd_duplicate(
args: &DuplicateArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
if !args.revisions_pos.is_empty() {
writeln!(
ui.warning_default(),
"Positional argument is deprecated. Use -r REVISION instead."
)?;
}
let to_duplicate: Vec<CommitId> =
if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() {
if !args.revisions.is_empty() || !args.revisions_pos.is_empty() {
workspace_command
.parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())?
.parse_union_revsets(ui, &[&*args.revisions, &*args.revisions_pos].concat())?
} else {
workspace_command.parse_revset(ui, &RevisionArg::AT)?
}
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,15 @@ When none of the `--destination`, `--insert-after`, or `--insert-before` argumen
When any of the `--destination`, `--insert-after`, or `--insert-before` arguments are provided, the roots of the specified commits will be duplicated onto the destination indicated by the arguments. Other specified commits will be duplicated onto these newly duplicated commits. If the `--insert-after` or `--insert-before` arguments are provided, the new children indicated by the arguments will be rebased onto the heads of the specified commits.
**Usage:** `jj duplicate [OPTIONS] [REVISIONS]...`
**Usage:** `jj duplicate [OPTIONS]`
###### **Arguments:**
* `<REVISIONS>` — The revision(s) to duplicate (default: @)
* `<REVISIONS>`
###### **Options:**
* `-r`, `--revisions <REVISIONS>` — The revision(s) to duplicate (default: @)
* `-d`, `--destination <DESTINATION>` — The revision(s) to duplicate onto (can be repeated to create a merge commit)
* `-A`, `--insert-after <INSERT_AFTER>` — The revision(s) to insert after (can be repeated to create a merge commit)
* `-B`, `--insert-before <INSERT_BEFORE>` — The revision(s) to insert before (can be repeated to create a merge commit)
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ fn test_short_prefix_in_transaction() {
}
// Create 2^4 duplicates of the chain
for _ in 0..4 {
test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]);
test_env.jj_cmd_ok(&repo_path, &["duplicate", "-rdescription(commit)"]);
}

// Short prefix should be used for commit summary inside the transaction
Expand Down
Loading

0 comments on commit a2eea49

Please sign in to comment.