Skip to content

Commit

Permalink
cli: add --untrack option to bookmark forget
Browse files Browse the repository at this point in the history
When untracking a remote bookmark, I usually also want to forget the
local bookmark associated with it, and there is no way to do this in a
single command currently. Instead, it's necessary to either untrack the
remote bookmark first and then delete the local bookmark, or forget the
bookmark first and then run `jj git fetch` to correct the remote
bookmark which is now missing.

Instead of adding `--untrack` to `jj bookmark forget`, we could add a
`--delete-local` option to `jj bookmark untrack`. This might be more
unintuitive in cases where there are multiple tracked remote bookmarks
though, since a user might forget to stop tracking one remote bookmark,
and then the deleted local bookmark might accidentally be pushed to that
remote. Therefore, it seems safer to add the flag here, since it's clear
that it untracks all of the remote bookmarks.
  • Loading branch information
scott2000 committed Feb 1, 2025
1 parent 66808e5 commit f7225e6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Conditional configuration now supports `--when.commands` to change configuration
based on subcommand.

* `jj bookmark forget` now accepts a `--untrack` flag to untrack remote
bookmarks instead of forgetting them.

### Fixed bugs

* `jj git fetch` with multiple remotes will now fetch from all remotes before
Expand Down
12 changes: 10 additions & 2 deletions cli/src/commands/bookmark/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ use crate::ui::Ui;
/// recreated on future pulls if it still exists in the remote.
#[derive(clap::Args, Clone, Debug)]
pub struct BookmarkForgetArgs {
/// Untrack remote bookmarks instead of forgetting them
#[arg(long, short)]
untrack: bool,

/// The bookmarks to forget
///
/// By default, the specified name matches exactly. Use `glob:` prefix to
Expand Down Expand Up @@ -61,8 +65,12 @@ pub fn cmd_bookmark_forget(
tx.repo_mut()
.set_local_bookmark_target(name, RefTarget::absent());
for (remote_name, _) in &bookmark_target.remote_refs {
tx.repo_mut()
.set_remote_bookmark(name, remote_name, RemoteRef::absent());
if args.untrack {
tx.repo_mut().untrack_remote_bookmark(name, remote_name);
} else {
tx.repo_mut()
.set_remote_bookmark(name, remote_name, RemoteRef::absent());
}
}
}
writeln!(ui.status(), "Forgot {} bookmarks.", matched_bookmarks.len())?;
Expand Down
3 changes: 3 additions & 0 deletions cli/src/commands/bookmark/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use crate::ui::Ui;
///
/// A non-tracking remote bookmark is just a pointer to the last-fetched remote
/// bookmark. It won't be imported as a local bookmark on future pulls.
///
/// If you want to forget a local bookmark while also untracking the
/// corresponding remote bookmarks, use `jj bookmark forget --untrack` instead.
#[derive(clap::Args, Clone, Debug)]
pub struct BookmarkUntrackArgs {
/// Remote bookmarks to untrack
Expand Down
8 changes: 7 additions & 1 deletion cli/tests/cli-reference@.md.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Forget everything about a bookmark, including its local and remote targets

A forgotten bookmark will not impact remotes on future pushes. It will be recreated on future pulls if it still exists in the remote.

**Usage:** `jj bookmark forget <NAMES>...`
**Usage:** `jj bookmark forget [OPTIONS] <NAMES>...`

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

Expand All @@ -348,6 +348,10 @@ A forgotten bookmark will not impact remotes on future pushes. It will be recrea

[wildcard pattern]: https://jj-vcs.github.io/jj/latest/revsets/#string-patterns

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

* `-u`, `--untrack` — Untrack remote bookmarks instead of forgetting them



## `jj bookmark list`
Expand Down Expand Up @@ -485,6 +489,8 @@ Stop tracking given remote bookmarks

A non-tracking remote bookmark is just a pointer to the last-fetched remote bookmark. It won't be imported as a local bookmark on future pulls.

If you want to forget a local bookmark while also untracking the corresponding remote bookmarks, use `jj bookmark forget --untrack` instead.

**Usage:** `jj bookmark untrack <BOOKMARK@REMOTE>...`

###### **Arguments:**
Expand Down
13 changes: 13 additions & 0 deletions cli/tests/test_bookmark_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,19 @@ fn test_bookmark_forget_fetched_bookmark() {
feature1: ooosovrs 38aefb17 (empty) another message
@origin: ooosovrs 38aefb17 (empty) another message
"###);

// TEST 4: If `--untrack` is used, the remote bookmark only be untracked
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "--untrack", "feature1"]);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
feature1@origin: ooosovrs 38aefb17 (empty) another message
"###);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(stdout, @"");
// There should be no output here since the remote bookmark wasn't forgotten
insta::assert_snapshot!(stderr, @"Nothing changed.");
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
feature1@origin: ooosovrs 38aefb17 (empty) another message
"###);
}

#[test]
Expand Down

0 comments on commit f7225e6

Please sign in to comment.