Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- `core.watchman.register_snapshot_trigger`
- `diff.format`

* Specifying multiple bookmark arguments for `jj bookmark move` is deprecated.
Moving multiple bookmarks at once can still be done with a string pattern.

### Deprecations

* `jj bisect run --command <cmd>` is deprecated in favor of
Expand Down
38 changes: 27 additions & 11 deletions cli/src/commands/bookmark/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,41 @@ use crate::command_error::user_error_with_hint;
use crate::complete;
use crate::ui::Ui;

/// Move existing bookmarks to target revision
/// Move an existing bookmark to a target revision
///
/// If bookmark names are given, the specified bookmarks will be updated to
/// If a bookmark name is given, the specified bookmark will be updated to
/// point to the target revision.
///
/// If `--from` options are given, bookmarks currently pointing to the
/// specified revisions will be updated. The bookmarks can also be filtered by
/// names.
/// name.
///
/// Example: pull up the nearest bookmarks to the working-copy parent
///
/// $ jj bookmark move --from 'heads(::@- & bookmarks())' --to @-
#[derive(clap::Args, Clone, Debug)]
#[command(group(clap::ArgGroup::new("source").multiple(true).required(true)))]
pub struct BookmarkMoveArgs {
/// Move bookmarks matching the given name patterns
/// Move bookmark matching the given name pattern
///
/// By default, the specified name matches exactly. Use `glob:` prefix to
/// select bookmarks by [wildcard pattern].
/// By default, the specified name matches exactly. Use the `glob:` or
/// `regex:` prefix to select multiple bookmarks by [string pattern].
///
/// [wildcard pattern]:
/// [string pattern]:
/// https://jj-vcs.github.io/jj/latest/revsets/#string-patterns
#[arg(
group = "source",
value_parser = StringPattern::parse,
add = ArgValueCandidates::new(complete::local_bookmarks),
)]
names: Vec<StringPattern>,
name: Option<StringPattern>,

// TODO: Delete in jj 0.41.0+
#[arg(
hide = true,
value_parser = StringPattern::parse,
)]
additional_names: Vec<StringPattern>,

/// Move bookmarks from the given revisions
#[arg(
Expand Down Expand Up @@ -85,6 +92,13 @@ pub fn cmd_bookmark_move(
command: &CommandHelper,
args: &BookmarkMoveArgs,
) -> Result<(), CommandError> {
if !args.additional_names.is_empty() {
writeln!(
ui.warning_default(),
"Using multiple bookmark arguments is deprecated. Use a string pattern \
('regex:foo|bar') or a shell loop instead."
)?;
}
let mut workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo().clone();
let target_commit = workspace_command.resolve_single_rev(ui, &args.to)?;
Expand All @@ -105,8 +119,10 @@ pub fn cmd_bookmark_move(
} else {
Box::new(|_| Ok(true))
};
let mut bookmarks = if !args.names.is_empty() {
find_bookmarks_with(&args.names, |pattern| {
let mut bookmarks = if let Some(name) = &args.name {
let mut names = args.additional_names.clone();
names.push(name.clone());
find_bookmarks_with(&names, |pattern| {
repo.view()
.local_bookmarks_matching(pattern)
.filter_map(|(name, target)| {
Expand Down Expand Up @@ -163,7 +179,7 @@ pub fn cmd_bookmark_move(
tx.write_commit_summary(formatter.as_mut(), &target_commit)?;
writeln!(formatter)?;
}
if matched_bookmarks.len() > 1 && args.names.is_empty() {
if matched_bookmarks.len() > 1 && args.name.is_none() {
writeln!(
ui.hint_default(),
"Specify bookmark by name to update just one of the bookmarks."
Expand Down
17 changes: 9 additions & 8 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ See [`jj help -k bookmarks`] for more information.
* `delete` — Delete an existing bookmark and propagate the deletion to remotes on the next push
* `forget` — Forget a bookmark without marking it as a deletion to be pushed
* `list` — List bookmarks and their targets
* `move` — Move existing bookmarks to target revision
* `move` — Move an existing bookmark to a target revision
* `rename` — Rename `old` bookmark name to `new` bookmark name
* `set` — Create or update a bookmark to point to a certain commit
* `track` — Start tracking given remote bookmarks
Expand Down Expand Up @@ -476,27 +476,28 @@ See [`jj help -k bookmarks`] for more information.

## `jj bookmark move`

Move existing bookmarks to target revision
Move an existing bookmark to a target revision

If bookmark names are given, the specified bookmarks will be updated to point to the target revision.
If a bookmark name is given, the specified bookmark will be updated to point to the target revision.

If `--from` options are given, bookmarks currently pointing to the specified revisions will be updated. The bookmarks can also be filtered by names.
If `--from` options are given, bookmarks currently pointing to the specified revisions will be updated. The bookmarks can also be filtered by name.

Example: pull up the nearest bookmarks to the working-copy parent

$ jj bookmark move --from 'heads(::@- & bookmarks())' --to @-

**Usage:** `jj bookmark move [OPTIONS] <NAMES|--from <REVSETS>>`
**Usage:** `jj bookmark move [OPTIONS] <NAME|--from <REVSETS>>`

**Command Alias:** `m`

###### **Arguments:**

* `<NAMES>` — Move bookmarks matching the given name patterns
* `<NAME>` — Move bookmark matching the given name pattern

By default, the specified name matches exactly. Use `glob:` prefix to select bookmarks by [wildcard pattern].
By default, the specified name matches exactly. Use the `glob:` or `regex:` prefix to select multiple bookmarks by [string pattern].

[wildcard pattern]: https://jj-vcs.github.io/jj/latest/revsets/#string-patterns
[string pattern]: https://jj-vcs.github.io/jj/latest/revsets/#string-patterns
* `<ADDITIONAL_NAMES>`

###### **Options:**

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_bookmark_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ fn test_bookmark_move_matching() {
insta::assert_snapshot!(output, @r"
------- stderr -------
error: the following required arguments were not provided:
<NAMES|--from <REVSETS>>
<NAME|--from <REVSETS>>

Usage: jj bookmark move <NAMES|--from <REVSETS>>
Usage: jj bookmark move <NAME|--from <REVSETS>>

For more information, try '--help'.
[EOF]
Expand Down