Skip to content
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

cli: warn user if they try to jj bookmark set bookmark@remote #5423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xdeafbeef
Copy link
Member

I'm not sure, maybe there is a legit use case for having @ in branch name, but most likely it's a mistake.

It's also not very consistent with other commands.
You can jj rebase -d br@origin, but you can't jj bookmark set br@origin after rebasing(I was lazy importing bookmark).

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@PhilipMetzger
Copy link
Contributor

PhilipMetzger commented Jan 21, 2025

Thanks for doing this. It would be nice if you also added the bookmark {set, create} errors as discussed on Discord and here.

Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

LG.

Another option is to parse bookmark name as revset symbol, so the user will need to quote bookmark name as `'"foo@bar"' if they really want to create a local bookmark of that name.

cli/src/commands/bookmark/set.rs Outdated Show resolved Hide resolved
cli/src/commands/bookmark/set.rs Outdated Show resolved Hide resolved
cli/tests/test_bookmark_at.rs Outdated Show resolved Hide resolved
@martinvonz
Copy link
Member

Another option is to parse bookmark name as revset symbol, so the user will need to quote bookmark name as `'"foo@bar"' if they really want to create a local bookmark of that name.

That would also catch cases like jj bookmark set foo- (which also creates a bookmark that's hard to refer to in revsets). That would be good. Feel like trying that @0xdeafbeef?

@0xdeafbeef 0xdeafbeef force-pushed the 0xdeafbeef/push-wxxxnkvrpxns branch 2 times, most recently from df4e93a to 88ed179 Compare January 22, 2025 20:10
@0xdeafbeef
Copy link
Member Author

Another option is to parse bookmark name as revset symbol, so the user will need to quote bookmark name as `'"foo@bar"' if they really want to create a local bookmark of that name.

That would also catch cases like jj bookmark set foo- (which also creates a bookmark that's hard to refer to in revsets). That would be good. Feel like trying that @0xdeafbeef?

i've added revset parsing

@0xdeafbeef 0xdeafbeef requested a review from yuja January 22, 2025 20:12
Comment on lines +275 to +273
fn parse(name: &str, helper: &WorkspaceCommandHelper) -> Result<Self, CommandError> {
let node = helper.parse_revset_expression(name)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, we can add public revset::parse_symbol() -> Result<String, ..> function that does parse_program() and expect_literal() (or reexport these functions.) Revset aliases shouldn't be expanded, and the other context parameters are unneeded.

Maybe we can add error hint by inspecting the source string? It might be easier if parsed tree (= result of parse_program()) is available, but I'm not sure.

Comment on lines 234 to 237
writeln!(
hint,
"To track remote bookmarks, use: jj bookmark --track {}",
remote_like.join(" ")
)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unparsable name can be just an error, not a warning. I think that's the idea of using revset parser. User can use escape syntax to specify weird bookmark name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unparsable name can be just an error, not a warning. I think that's the idea of using revset parser. User can use escape syntax to specify weird bookmark name.

Sorry, I didn't get it. The only reason to use a revset parser is not to reinvent my own :)
You want to return an error for cases when name was sucessfully parsed as revset(except legit cases) and when it was not parsed?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think Yuya just meant the since we're using the real revset parser, we can make it an error. If we had some naive check instead, we might have wanted to make it a warning so we don't prevent valid names. But I'm not 100% sure that's what he meant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

without shell escaping:

  • foo@bar -> error
  • "foo@bar" -> local bookmark foo@bar
  • foo- -> error
  • "foo-" -> local bookmark foo-
  • (foo) -> could be an error (but might be okay to parse as local bookmark foo)

CHANGELOG.md Outdated
@@ -115,6 +115,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

* New `subject(pattern)` revset function that matches first line of commit
descriptions.
* Warn user if he tries to use `jj boookmark set branch@remote`
Copy link
Member

Choose a reason for hiding this comment

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

nit: "he tries" -> "they try"

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}
drop(writer);

let mut hint = ui.hint_default();
Copy link
Member

Choose a reason for hiding this comment

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

nit: we usually inline these where they're used, so just call ui.hint_default() on line 235 etc

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@0xdeafbeef 0xdeafbeef force-pushed the 0xdeafbeef/push-wxxxnkvrpxns branch from 88ed179 to aa06bfd Compare January 26, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants