Skip to content

Commit

Permalink
cli: provide short flags for rev ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Nov 20, 2024
1 parent c0a9e20 commit ac0e531
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* The `tags()` revset function now takes an optional `pattern` argument,
mirroring that of `bookmarks()`.

* Several commands now support `-f/-t` shorthands for `--from/--to`:
- `diff`
- `diffedit`
- `interdiff`
- `op diff`
- `restore`

### Fixed bugs

* `jj config unset <TABLE-NAME>` no longer removes a table (such as `[ui]`.)
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ pub(crate) struct DiffArgs {
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
revision: Option<RevisionArg>,
/// Show changes from this revision
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(long, short, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
from: Option<RevisionArg>,
/// Show changes to this revision
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(long, short, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
to: Option<RevisionArg>,
/// Restrict the diff to these paths
#[arg(value_hint = clap::ValueHint::AnyPath)]
Expand Down
12 changes: 10 additions & 2 deletions cli/src/commands/diffedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ pub(crate) struct DiffeditArgs {
/// Show changes from this revision
///
/// Defaults to @ if --to is specified.
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(
long, short,
conflicts_with = "revision",
add = ArgValueCandidates::new(complete::all_revisions),
)]
from: Option<RevisionArg>,
/// Edit changes in this revision
///
/// Defaults to @ if --from is specified.
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::mutable_revisions))]
#[arg(
long, short,
conflicts_with = "revision",
add = ArgValueCandidates::new(complete::mutable_revisions),
)]
to: Option<RevisionArg>,
/// Specify diff editor to be used
#[arg(long, value_name = "NAME")]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/interdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ use crate::ui::Ui;
#[command(mut_arg("ignore_space_change", |a| a.short('b')))]
pub(crate) struct InterdiffArgs {
/// Show changes from this revision
#[arg(long, add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
from: Option<RevisionArg>,
/// Show changes to this revision
#[arg(long, add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
to: Option<RevisionArg>,
/// Restrict the diff to these paths
#[arg(value_hint = clap::ValueHint::AnyPath)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/operation/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ pub struct OperationDiffArgs {
operation: Option<String>,
/// Show repository changes from this operation
#[arg(
long,
long, short,
conflicts_with = "operation",
add = ArgValueCandidates::new(complete::operations),
)]
from: Option<String>,
/// Show repository changes to this operation
#[arg(
long,
long, short,
conflicts_with = "operation",
add = ArgValueCandidates::new(complete::operations),
)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub(crate) struct RestoreArgs {
#[arg(value_hint = clap::ValueHint::AnyPath)]
paths: Vec<String>,
/// Revision to restore from (source)
#[arg(long, add = ArgValueCandidates::new(complete::all_revisions))]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
from: Option<RevisionArg>,
/// Revision to restore into (destination)
#[arg(long, add = ArgValueCandidates::new(complete::mutable_revisions))]
#[arg(long, short, add = ArgValueCandidates::new(complete::mutable_revisions))]
to: Option<RevisionArg>,
/// Undo the changes in a revision as compared to the merge of its parents.
///
Expand Down
21 changes: 11 additions & 10 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: cli/tests/test_generate_md_cli_help.rs
description: "AUTO-GENERATED FILE, DO NOT EDIT. This cli reference is generated by a test as an `insta` snapshot. MkDocs includes this snapshot from docs/cli-reference.md."
snapshot_kind: text
---
<!-- BEGIN MARKDOWN-->

Expand Down Expand Up @@ -689,8 +690,8 @@ With the `--from` and/or `--to` options, shows the difference from/to the given
* `-r`, `--revision <REVISION>` — Show changes in this revision, compared to its parent(s)
If the revision is a merge commit, this shows changes *from* the automatic merge of the contents of all of its parents *to* the contents of the revision itself.
* `--from <FROM>` — Show changes from this revision
* `--to <TO>` — Show changes to this revision
* `-f`, `--from <FROM>` — Show changes from this revision
* `-t`, `--to <TO>` — Show changes to this revision
* `-s`, `--summary` — For each path, show only whether it was modified, added, or deleted
* `--stat` — Show a histogram of the changes
* `--types` — For each path, show only its type before and after
Expand Down Expand Up @@ -729,10 +730,10 @@ See `jj restore` if you want to move entire files from one revision to another.
* `-r`, `--revision <REVISION>` — The revision to touch up
Defaults to @ if neither --to nor --from are specified.
* `--from <FROM>` — Show changes from this revision
* `-f`, `--from <FROM>` — Show changes from this revision
Defaults to @ if --to is specified.
* `--to <TO>` — Edit changes in this revision
* `-t`, `--to <TO>` — Edit changes in this revision
Defaults to @ if --from is specified.
* `--tool <NAME>` — Specify diff editor to be used
Expand Down Expand Up @@ -1316,8 +1317,8 @@ This excludes changes from other commits by temporarily rebasing `--from` onto `
###### **Options:**
* `--from <FROM>` — Show changes from this revision
* `--to <TO>` — Show changes to this revision
* `-f`, `--from <FROM>` — Show changes from this revision
* `-t`, `--to <TO>` — Show changes to this revision
* `-s`, `--summary` — For each path, show only whether it was modified, added, or deleted
* `--stat` — Show a histogram of the changes
* `--types` — For each path, show only its type before and after
Expand Down Expand Up @@ -1510,8 +1511,8 @@ Compare changes to the repository between two operations
###### **Options:**
* `--operation <OPERATION>` — Show repository changes in this operation, compared to its parent
* `--from <FROM>` — Show repository changes from this operation
* `--to <TO>` — Show repository changes to this operation
* `-f`, `--from <FROM>` — Show repository changes from this operation
* `-t`, `--to <TO>` — Show repository changes to this operation
* `--no-graph` — Don't show the graph, show a flat list of modified changes
* `-p`, `--patch` — Show patch of modifications to changes
Expand Down Expand Up @@ -1913,8 +1914,8 @@ See `jj diffedit` if you'd like to restore portions of files rather than entire
###### **Options:**
* `--from <FROM>` — Revision to restore from (source)
* `--to <TO>` — Revision to restore into (destination)
* `-f`, `--from <FROM>` — Revision to restore from (source)
* `-t`, `--to <TO>` — Revision to restore into (destination)
* `-c`, `--changes-in <REVISION>` — Undo the changes in a revision as compared to the merge of its parents.
This undoes the changes that can be seen with `jj diff -r REVISION`. If `REVISION` only has a single parent, this option is equivalent to `jj restore --to REVISION --from REVISION-`.
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,15 @@ fn test_help() {
let test_env = TestEnvironment::default();

let stdout = test_env.jj_cmd_success(test_env.env_root(), &["diffedit", "-h"]);
insta::assert_snapshot!(stdout, @r#"
insta::assert_snapshot!(stdout, @r"
Touch up the content changes in a revision with a diff editor
Usage: jj diffedit [OPTIONS]
Options:
-r, --revision <REVISION> The revision to touch up
--from <FROM> Show changes from this revision
--to <TO> Edit changes in this revision
-f, --from <FROM> Show changes from this revision
-t, --to <TO> Edit changes in this revision
--tool <NAME> Specify diff editor to be used
--restore-descendants Preserve the content (not the diff) when rebasing descendants
-h, --help Print help (see more with '--help')
Expand All @@ -665,7 +665,7 @@ fn test_help() {
--quiet Silence non-primary command output
--no-pager Disable the pager
--config-toml <TOML> Additional configuration options (can be repeated)
"#);
");
}

#[test]
Expand Down

0 comments on commit ac0e531

Please sign in to comment.