Skip to content

cli: git push: show hint when there are bookmarks pending deletion #6332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -45,6 +45,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Added `duplicate_description` template, which allows [customizing the descriptions
of the commits `jj duplicate` creates](docs/config.md#duplicate-commit-description).

* `jj git push` now shows a hint to use `--deleted` if there are bookmarks
pending deletion.

### Fixed bugs

* Fixed crash on change-delete conflict resolution.
Expand Down
21 changes: 21 additions & 0 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,27 @@ pub fn cmd_git_push(
),
remote = remote.as_symbol()
);

// We only show this hint when pushing with no arguments because if the user is
// explicitly selecting a tracked bookmark with `--revisions`, then they'll get
// an error instructing them to use `--deleted`.
if use_default_revset {
let deleted_bookmarks = tx
.repo()
.view()
.local_remote_bookmarks(remote)
.filter(|(_, targets)| {
targets.local_target.is_absent() && targets.remote_ref.is_tracked()
})
.count();

if deleted_bookmarks > 0 {
writeln!(
ui.hint_default(),
"You can push {deleted_bookmarks} deleted bookmark(s) with `--deleted`"
)?;
}
}
}
if bookmark_updates.is_empty() {
writeln!(ui.status(), "Nothing changed.")?;
Expand Down
8 changes: 8 additions & 0 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,14 @@ fn test_git_push_deleted(subprocess: bool) {
work_dir
.run_jj(["bookmark", "delete", "bookmark1"])
.success();
let output = work_dir.run_jj(["git", "push"]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add a comment here explaining what exactly this is testing for, like elsewhere in this file?

insta::assert_snapshot!(output, @r"
------- stderr -------
Warning: No bookmarks found in the default push revset: remote_bookmarks(remote=origin)..@
Hint: You can push 1 deleted bookmark(s) with `--deleted`
Nothing changed.
[EOF]
");
let output = work_dir.run_jj(["git", "push", "--deleted"]);
insta::allow_duplicates! {
insta::assert_snapshot!(output, @r"
Expand Down