-
Notifications
You must be signed in to change notification settings - Fork 319
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: Upsert branch (update branch or create if it does not exist) #3584
Comments
I believe we've pretty much achieved consensus on adding It should be fairly straightforward to add if you want to give it a try (check the existing implementations for |
Why have two separate subcommands ( |
@joyously only from an implementation perspective, I think.
|
I think it's okay to deprecate |
I agree with making The end result of both commands is the same: a branch exists and is set to a revision. I can't think of any use case where we would want to throw an error when setting a branch that doesn't exist. We could add a Once the we decide on the behavior, I can take up creating the PR. |
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
(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'm all for this, but you still have the problem of defining what it is and how it works. If |
My opinion on the whole 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. |
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 Using |
To be clear, I don't mean [EDIT] I was wondering if we would add |
I've opened a PR to add the create option to set: #3585 I think the best point for this is that adding Another alternative could be prompting the user in the CLI to create the branch after |
I'm a little late to the discussion, but we could have (Indeed, as Waleed mentioned, I do regularly make typos and care about them) |
From my usage, it's often that I want to quickly create a branch after seeing it doesn't exist. For example:
Edit: Additionally, it matches the behaviour of other tools like |
That's a good point, |
(I thought |
I think the point was that adding |
Yeah, I agree, but if the user doesn't want to overwrite an existing branch, he doesn't have to try |
… name This basically supersedes the current "branch set" command. The plan is to turn "branch set" into an "upsert" command, and deprecate "branch create". (martinvonz#3584) Maybe we can also add "branch set --new" flag to only allow creation of new branches. One reason behind this proposed change is that "set" usually allows both "creation" and "update". However, we also need a typo-safe version of "set" to not create new branches by accident. "jj branch move" is useful when advancing ancestor branches. Let's say you've added a couple of commits on top of an existing PR branch, you can advance the branch by "jj branch move --from 'heads(::@- & branches())' --to @-". If this pattern is super common, maybe we can add --advance flag for short. One drawback of this change is that "git branch --move" is equivalent to "jj branch rename". I personally don't find this is confusing, but it's true that "move" sometimes means "rename".
… name This basically supersedes the current "branch set" command. The plan is to turn "branch set" into an "upsert" command, and deprecate "branch create". (martinvonz#3584) Maybe we can also add "branch set --new" flag to only allow creation of new branches. One reason behind this proposed change is that "set" usually allows both "creation" and "update". However, we also need a typo-safe version of "set" to not create new branches by accident. "jj branch move" is useful when advancing ancestor branches. Let's say you've added a couple of commits on top of an existing PR branch, you can advance the branch by "jj branch move --from 'heads(::@- & branches())' --to @-". If this pattern is super common, maybe we can add --advance flag for short. One drawback of this change is that "git branch --move" is equivalent to "jj branch rename". I personally don't find this is confusing, but it's true that "move" sometimes means "rename".
… name This basically supersedes the current "branch set" command. The plan is to turn "branch set" into an "upsert" command, and deprecate "branch create". (martinvonz#3584) Maybe we can also add "branch set --new" flag to only allow creation of new branches. One reason behind this proposed change is that "set" usually allows both "creation" and "update". However, we also need a typo-safe version of "set" to not create new branches by accident. "jj branch move" is useful when advancing ancestor branches. Let's say you've added a couple of commits on top of an existing PR branch, you can advance the branch by "jj branch move --from 'heads(::@- & branches())' --to @-". If this pattern is super common, maybe we can add --advance flag for short. One drawback of this change is that "git branch --move" is equivalent to "jj branch rename". I personally don't find this is confusing, but it's true that "move" sometimes means "rename".
… name This basically supersedes the current "branch set" command. The plan is to turn "branch set" into an "upsert" command, and deprecate "branch create". (#3584) Maybe we can also add "branch set --new" flag to only allow creation of new branches. One reason behind this proposed change is that "set" usually allows both "creation" and "update". However, we also need a typo-safe version of "set" to not create new branches by accident. "jj branch move" is useful when advancing ancestor branches. Let's say you've added a couple of commits on top of an existing PR branch, you can advance the branch by "jj branch move --from 'heads(::@- & branches())' --to @-". If this pattern is super common, maybe we can add --advance flag for short. One drawback of this change is that "git branch --move" is equivalent to "jj branch rename". I personally don't find this is confusing, but it's true that "move" sometimes means "rename".
I've added I was thinking of introducing the following changes, but (1) can be footgun for existing users. So even if we plan to change the default behavior, it's better to keep the current behavior (with deprecation warning) for a moment.
Reasons for (1):
Reasons for (2) and (3):
I'm getting less sure about (2) and (3). Another more controversial idea is:
The motivation for the rename is that "create" has stronger implication than "set", so it's difficult to extend the behavior by adding command-line flags. However, we want flags because it's easier to type than replacing command name. Related discussions: |
Since "set <thing>" often adds a <thing> as needed, it make some sense that "branch set" does upsert. The added flag helps re-execute a failed "set" command to create new branch. I'm hoping to make it the default by migrating existing "branch set" users to "branch move", but changing the default behavior right now can cause problems. So, let's add an opt-in flag first. Closes martinvonz#3584
Since "set <thing>" often adds a <thing> if not exists, it make some sense that "branch set" does upsert. The current "branch set" use case is now covered by "branch move", so it's okay to change the "set" behavior. If new branch is created by "branch set", status message and hint will be printed to help migration. The user should be able to undo creation if it was a mistake. Closes martinvonz#3584
## [0.19.0] - 2024-07-03 ### Breaking changes * In revset aliases, top-level `kind:pattern` expression is now parsed as modifier. Surround with parentheses if it should be parsed as string/file pattern. * Dropped support for automatic upgrade of repo formats used by versions before 0.12.0. * `jj fix` now defaults to the broader revset `-s reachable(@, mutable())` instead of `-s @`. * Dropped support for deprecated `jj branch delete`/`forget` `--glob` option. * `jj branch set` now creates new branch if it doesn't exist. Use `jj branch move` to ensure that the target branch already exists. [#3584](martinvonz/jj#3584) ### Deprecations * Replacing `-l` shorthand for `--limit` with `-n` in `jj log`, `jj op log` and `jj obslog`. * `jj split --siblings` is deprecated in favor of `jj split --parallel` (to match `jj parallelize`). * A new `jj file` subcommand now replaces several existing uncategorized commands, which are deprecated. - `jj file show` replaces `jj cat`. - `jj file chmod` replaces `jj chmod`. - `jj file list` replaces `jj files`. ### New features * Support background filesystem monitoring via watchman triggers enabled with the `core.watchman.register_snapshot_trigger = true` config. * Show paths to config files when configuration errors occur. * `jj fix` now supports configuring the default revset for `-s` using the `revsets.fix` config. * The `descendants()` revset function now accepts an optional `depth` argument; like the `ancestors()` depth argument, it limits the depth of the set. * Revset/template aliases now support function overloading. [#2966](martinvonz/jj#2966) * Conflicted files are individually simplified before being materialized. * The `jj file` subcommand now contains several existing file utilities. - `jj file show`, replacing `jj cat`. - `jj file chmod` replacing `jj chmod`. - `jj file list` replacing `jj files`. * New command `jj branch move` let you update branches by name pattern or source revision. * New diff option `jj diff --name-only` allows for easier shell scripting. * In color-words diffs, hunks are now highlighted with underline. See [diff colors and styles](docs/config.md#diff-colors-and-styles) for customization. * `jj git push -c <arg>` can now accept revsets that resolve to multiple revisions. This means that `jj git push -c xyz -c abc` is now equivalent to `jj git push -c 'all:(xyz | abc)'`. * `jj prev` and `jj next` have gained a `--conflict` flag which moves you to the next conflict in a child commit. * New command `jj git remote set-url` that sets the url of a git remote. * Author timestamp is now reset when rewriting discardable commits (empty commits with no description) if authored by the current user. [#2000](martinvonz/jj#2000) * `jj commit` now accepts `--reset-author` option to match `jj describe`. * `jj squash` now accepts a `--keep-emptied` option to keep the source commit. ### Fixed bugs * `jj git push` now ignores immutable commits when checking whether a to-be-pushed commit has conflicts, or has no description / committer / author set. [#3029](martinvonz/jj#3029) * `jj` will look for divergent changes outside the short prefix set even if it finds the change id inside the short prefix set. [#2476](martinvonz/jj#2476)
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 aError: No such branch
error. I then need to change the command tojj 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).The text was updated successfully, but these errors were encountered: