jj: FR: Upsert branch (update branch or create if it does not exist)
Is your feature request related to a problem? Please describe. When working with Git, I need to remember if a branch is already created before updating it.
For example, jj branch set my-branch -r @- gives a Error: No such branch error. I then need to change the command to jj branch create my-branch -r @-
Describe the solution you’d like
An option on jj branch set such as -c/--create to create the branch if it does not exist.
Example: jj branch set my branch -r @- -c
Describe alternatives you’ve considered
Writing a shell alias for jj branch set $args || jj branch create $args (pseudo-code).
About this issue
- Original URL
- State: open
- Created 2 months ago
- Comments: 15
I’m a little late to the discussion, but we could have
jj branch moveto move branches (whatsetdoes now) andjj branch setto move or create branches.(Indeed, as Waleed mentioned, I do regularly make typos and care about them)
I think there’s a good amount of reflection from @arxanas’s post, but I think there’s also one element missing: just because how people work with computers changes doesn’t mean everything should adapt. I think keeping creation and setting separate makes a lot of sense from a correctness standpoint. I’d much more strongly prefer we use
--allow-newinstead of--create, to encourage creating branches (or topics, or whatever they become) explicitly.Using
branch set --createas a default will lead to people blurring out the fact that they are opening themselves to creating new branches, because they’ll mentally erase--createwhen they think they aren’t actually going to be creating.branch set --allow-newdoesn’t have the risk of seeing--allow-newas not being part of the specific context, as it’s adding permission, not changing the nature of the operation, from the user’s perspective.My opinion on the whole
create/setsplit is that it generally helps users like myself who tend to litter the branch names with typos. It was really nice whenbranch setstopped to create seemingly “correct” branches, which were just typos. I’m in general for keeping bothjj branch set --createandjj branch create, as they’re a good UI. (See a previous discussion here)I’m also in favor of renaming the current branches concept to bookmarks, as they’re totally misleading for long term Git users, and actually accurately describing the current behavior.
The typo problem is addressed for the case when you’ve typoed a branch name but accidentally produced another valid branch name (which happens), but it doesn’t address the case when you create a new branch entirely unintentionally. (I recall cases earlier in my career where I spent some time trying to figure out, for example, why a push wasn’t doing anything, where it turned out that I didn’t actually update the branch that I thought I did, although this is somewhat mitigated by better tools for visualization.) (cc @ilyagr who I thought had complained about typos as well?)
The most obvious error case is when someone makes a typo in a branch name and they intended to update an existing branch.
I’m opposed to making
setthe default way to create branches unlesstouchcommand is also a primary way to create files? Does that resemble how anyone uses the filesystem in a GUI? They are very different; only Unixbrains would consider them the same operation. I think we should re-examine many of those biases, natural to us, before we bring them into jj, which might server a broader audience.jj setto create) is likely more convenient than having separate commands, so I don’t think this criterion is contended.createfor discoverability, even ifset --createexists: https://github.com/martinvonz/jj/issues/3518#issuecomment-2067770819(Another solution is to completely drop branches as a core feature, adopt topics or something else, and stop worrying about whether the branch UI makes sense 🤣)
I think it’s okay to deprecate
branch createif we addset --create/--allow-new. To me, the verbsetcan also mean creation, and the typo problem is mostly addressed by requiring--allowflags for unusual movements.@joyously only from an implementation perspective, I think.
INSERTandUPDATEare distinct operations, and you can’t use them interchangeably.I believe we’ve pretty much achieved consensus on adding
--createtojj branch set, just nobody has implemented it yet.It should be fairly straightforward to add if you want to give it a try (check the existing implementations for
setandcreate; I wouldn’t be surprised ifsethad a specific check that the branch exists first, which you could just omit in this case — that’s howsetused to function.)