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

FR: error out when creating branches with @ in the name #4358

Open
jalil-salame opened this issue Aug 29, 2024 · 6 comments
Open

FR: error out when creating branches with @ in the name #4358

jalil-salame opened this issue Aug 29, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@jalil-salame
Copy link

Is your feature request related to a problem? Please describe.
I have accidentally created branches when I wanted to move a remote branch (e.g. jj branch set branch@origin -r @-). This usually happens when I want to set it to a specific change with the -r option, as jj branch move uses the --to flag instead of the -r flag.

Describe the solution you'd like
Fail to create branches with @ in the name by default (I assume git allows creating branches with @s in the name so you want to still be able to use/create such branches, but not by default).

Describe alternatives you've considered

  • Add -r/--revision as an alias to --to in jj branch move
  • Disable branch creation on set without a flag (e.g. jj branch set --create-if-missing new-branch)
@bnjmnt4n
Copy link
Member

There's some prior discussion in #3932, but I believe the consensus is that jj branch set can set the branch (creating one if it doesn't already exist, and giving a warning to use jj branch move if the intent is not to create new branches). I guess it might be possible to add a -r flag to jj branch move, but that doesn't fully align with the --from and --to argument names as well (which is why I think --to was chosen).

Even so, I believe there's an error in your initial issue: you can't "move" a remote branch locally. The only way to do that is to move the local tracking branch to the desired commit (via jj branch set/move) and jj git push to push the branch and update the remote branch. (#3588 is a feature request for pushing a specific commit directly to the given branch, which might be what you're looking for.)

@yuja
Copy link
Contributor

yuja commented Aug 29, 2024

as jj branch move uses the --to flag instead of the -r flag.

Do you want -r specifically? or is it okay if --to had a short flag? We have --from/--to combinations in various commands, and it'll probably make sense to add short names for them.

@jalil-salame jalil-salame changed the title FR: error out when creaating branches with @ in the name FR: error out when creating branches with @ in the name Aug 29, 2024
@jalil-salame
Copy link
Author

as jj branch move uses the --to flag instead of the -r flag.

Do you want -r specifically? or is it okay if --to had a short flag? We have --from/--to combinations in various commands, and it'll probably make sense to add short names for them.

Short flags would be nice

@jalil-salame
Copy link
Author

There's some prior discussion in #3932, but I believe the consensus is that jj branch set can set the branch (creating one if it doesn't already exist, and giving a warning to use jj branch move if the intent is not to create new branches). I guess it might be possible to add a -r flag to jj branch move, but that doesn't fully align with the --from and --to argument names as well (which is why I think --to was chosen).

I still believe this should be an error by default (creating a branch with an @ in the name).

Even so, I believe there's an error in your initial issue: you can't "move" a remote branch locally. The only way to do that is to move the local tracking branch to the desired commit (via jj branch set/move) and jj git push to push the branch and update the remote branch. (#3588 is a feature request for pushing a specific commit directly to the given branch, which might be what you're looking for.)

And it should probably be an error if I try to move a remote tracking branch c:

@yuja
Copy link
Contributor

yuja commented Aug 29, 2024

I still believe this should be an error by default (creating a branch with an @ in the name).

I don't think it should be an error (because @ is a valid branch name), but I understand it's confusing. Perhaps, a warning can be emitted if a branch name contained a certain meta characters (such as :, @, *, ?.)

@PhilipMetzger PhilipMetzger added the enhancement New feature or request label Aug 29, 2024
@tim-janik
Copy link
Contributor

I still believe this should be an error by default (creating a branch with an @ in the name).

I don't think it should be an error (because @ is a valid branch name), but I understand it's confusing. Perhaps, a warning can be emitted if a branch name contained a certain meta characters (such as :, @, *, ?.)

We already issue warnings for invalid branch names.
But the current behavior makes it much easier to create "invalid" bookmarks (i.e. ones that cannot be exported to git) than to get rid of them. E.g.

Foo="$(ls)" # accidental contents
jj b c "$FOO" # works with warning
jj b d "$FOO" # will error, hint suggests to us exact:

Problems occur if something like jj log -r @ is part of the prompt, and a bookmark is created with many newlines (due to an accident like above).
It would be nice if "invalid" bookmark creation was as hard as deletion, i.e. I'd like to see jj b c "$FOO" apply the same rule as jj b d "$FOO" and require an exact: prefix.

Related, bookmarks with invalid characters cannot be exported to git (which produces a warning), further info on valid git refs can be found here: https://git-scm.com/docs/git-check-ref-format
Rule 9 says "They cannot be the single character @"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants