Skip to content

Commit c3da5a1

Browse files
committed
cli: git push: show hint when there are bookmarks pending deletion
This comes from a personal experience where the following sequence of events happened: 1. `jj git push -c @-` 2. Oops, that was the wrong one, so I'll `jj bookmark delete` and `jj git push` 3. Hm... why didn't that do anything? Oh, right, `--deleted` As described in the diff, this hint only fires when `jj git push` is used with no arguments, as any user that passes `--all`, `--tracked`, or `--revisions` (targeting a deleted bookmark) will already get an error instructing them to use `--deleted`.
1 parent ee0e86f commit c3da5a1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4242
template, to the commit description. Use cases include DCO Sign Off and
4343
Gerrit Change Id.
4444

45+
* `jj git push` now shows a hint to use `--deleted` if there are bookmarks
46+
pending deletion.
47+
4548
### Fixed bugs
4649

4750
* Fixed crash on change-delete conflict resolution.

cli/src/commands/git/push.rs

+21
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,27 @@ pub fn cmd_git_push(
393393
),
394394
remote = remote.as_symbol()
395395
);
396+
397+
// We only show this hint when pushing with no arguments because if the user is
398+
// explicitly selecting a tracked bookmark with `--revisions`, then they'll get
399+
// an error instructing them to use `--deleted`.
400+
if use_default_revset {
401+
let deleted_bookmarks = tx
402+
.repo()
403+
.view()
404+
.local_remote_bookmarks(remote)
405+
.filter(|(_, targets)| {
406+
targets.local_target.is_absent() && targets.remote_ref.is_tracked()
407+
})
408+
.count();
409+
410+
if deleted_bookmarks > 0 {
411+
writeln!(
412+
ui.hint_default(),
413+
"You can push {deleted_bookmarks} deleted bookmark(s) with `--deleted`"
414+
)?;
415+
}
416+
}
396417
}
397418
if bookmark_updates.is_empty() {
398419
writeln!(ui.status(), "Nothing changed.")?;

cli/tests/test_git_push.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,14 @@ fn test_git_push_deleted(subprocess: bool) {
19611961
work_dir
19621962
.run_jj(["bookmark", "delete", "bookmark1"])
19631963
.success();
1964+
let output = work_dir.run_jj(["git", "push"]);
1965+
insta::assert_snapshot!(output, @r"
1966+
------- stderr -------
1967+
Warning: No bookmarks found in the default push revset: remote_bookmarks(remote=origin)..@
1968+
Hint: You can push 1 deleted bookmark(s) with `--deleted`
1969+
Nothing changed.
1970+
[EOF]
1971+
");
19641972
let output = work_dir.run_jj(["git", "push", "--deleted"]);
19651973
insta::allow_duplicates! {
19661974
insta::assert_snapshot!(output, @r"

0 commit comments

Comments
 (0)