Skip to content

Commit

Permalink
bookmarks: Make target revision a required argument to bookmark creat…
Browse files Browse the repository at this point in the history
…e/move/set.

This change is not backwards compatible, but it should be very easy to adapt to it.

This fixes
#5374
See also
#5363
  • Loading branch information
drieber committed Jan 31, 2025
1 parent 0f1a6fc commit aff9a32
Show file tree
Hide file tree
Showing 41 changed files with 440 additions and 330 deletions.
16 changes: 11 additions & 5 deletions cli/src/commands/bookmark/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ pub fn cmd_bookmark_create(
args: &BookmarkCreateArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let target_commit = workspace_command
.resolve_single_rev(ui, args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;

if args.revision.is_none() {
return Err(user_error_with_hint(
format!("Target revision not specified."),
"Use -r to specify the target revision.",
));
}

let target_commit =
workspace_command.resolve_single_rev(ui, args.revision.as_ref().unwrap())?;

let view = workspace_command.repo().view();
let bookmark_names = &args.names;
for name in bookmark_names {
Expand Down Expand Up @@ -90,9 +99,6 @@ pub fn cmd_bookmark_create(
tx.write_commit_summary(formatter.as_mut(), &target_commit)?;
writeln!(formatter)?;
}
if bookmark_names.len() > 1 && args.revision.is_none() {
writeln!(ui.hint_default(), "Use -r to specify the target revision.")?;
}

tx.finish(
ui,
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/bookmark/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub struct BookmarkMoveArgs {
// support `-f` for `--from`.
#[arg(
long,
default_value = "@",
value_name = "REVSET",
add = ArgValueCandidates::new(complete::all_revisions),
)]
Expand Down
12 changes: 10 additions & 2 deletions cli/src/commands/bookmark/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ pub fn cmd_bookmark_set(
args: &BookmarkSetArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let target_commit = workspace_command
.resolve_single_rev(ui, args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;

if args.revision.is_none() {
return Err(user_error_with_hint(
format!("Target revision not specified."),
"Use -r to specify the target revision.",
));
}

let target_commit =
workspace_command.resolve_single_rev(ui, args.revision.as_ref().unwrap())?;
let repo = workspace_command.repo().as_ref();
let bookmark_names = &args.names;
let mut new_bookmark_count = 0;
Expand Down
4 changes: 1 addition & 3 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Example: pull up the nearest bookmarks to the working-copy parent

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

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

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

Expand All @@ -421,8 +421,6 @@ $ jj bookmark move --from 'heads(::@- & bookmarks())' --to @-

* `--from <REVSETS>` — Move bookmarks from the given revisions
* `--to <REVSET>` — Move bookmarks to this revision

Default value: `@`
* `-B`, `--allow-backwards` — Allow moving bookmarks backwards or sideways


Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_abandon_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, paren
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_ok(repo_path, &["bookmark", "create", name]);
test_env.jj_cmd_ok(repo_path, &["bookmark", "create", name, "-r", "@"]);
}

#[test]
Expand Down
10 changes: 8 additions & 2 deletions cli/tests/test_advance_bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ fn test_advance_bookmarks_at_minus(make_commit: CommitFn) {
let workspace_path = test_env.env_root().join("repo");

set_advance_bookmarks(&test_env, true);
test_env.jj_cmd_ok(&workspace_path, &["bookmark", "create", "test_bookmark"]);
test_env.jj_cmd_ok(
&workspace_path,
&["bookmark", "create", "test_bookmark", "-r", "@"],
);

insta::allow_duplicates! {
insta::assert_snapshot!(get_log_output_with_bookmarks(&test_env, &workspace_path), @r###"
Expand All @@ -134,7 +137,10 @@ fn test_advance_bookmarks_at_minus(make_commit: CommitFn) {

// Create a second bookmark pointing to @. On the next commit, only the first
// bookmark, which points to @-, will advance.
test_env.jj_cmd_ok(&workspace_path, &["bookmark", "create", "test_bookmark2"]);
test_env.jj_cmd_ok(
&workspace_path,
&["bookmark", "create", "test_bookmark2", "-r", "@"],
);
make_commit(&test_env, &workspace_path, "second");
insta::allow_duplicates! {
insta::assert_snapshot!(get_log_output_with_bookmarks(&test_env, &workspace_path), @r###"
Expand Down
5 changes: 4 additions & 1 deletion cli/tests/test_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ fn test_alias_basic() {
let repo_path = test_env.env_root().join("repo");

test_env.add_config(r#"aliases.bk = ["log", "-r", "@", "-T", "bookmarks"]"#);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);
test_env.jj_cmd_ok(
&repo_path,
&["bookmark", "create", "my-bookmark", "-r", "@"],
);
let stdout = test_env.jj_cmd_success(&repo_path, &["bk"]);
insta::assert_snapshot!(stdout, @r###"
@ my-bookmark
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_backout_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn create_commit(
for (name, contents) in files {
std::fs::write(repo_path.join(name), contents).unwrap();
}
test_env.jj_cmd_ok(repo_path, &["bookmark", "create", name]);
test_env.jj_cmd_ok(repo_path, &["bookmark", "create", "-r@", name]);
}

#[test]
Expand Down
Loading

0 comments on commit aff9a32

Please sign in to comment.