Skip to content

Conversation

axosoft-ramint
Copy link
Contributor

Closes #3542

Automatically chooses the -b flag or not based on if your chosen branch is already in a worktree.

Also, if the -b flag does apply, shows the "new branch name" prompt before the confirm step.

- Auto-chooses "for new branch" option or not based on whether the chosen branch is already in a worktree.
- If "new branch" option is chosen, shows prompt for new branch name before reaching the confirm step.
@axosoft-ramint axosoft-ramint added the area-worktrees Issues or features related to worktrees label Sep 9, 2024
@d13 d13 self-requested a review September 9, 2024 18:02
@axosoft-ramint
Copy link
Contributor Author

axosoft-ramint commented Sep 11, 2024

To test:

  1. Use "create worktree" on a local branch that doesn't have a worktree. It should not prompt you for a branch name, and should just use the branch's name.
  2. Use "create worktree" on a local branch which already has a worktree. It should automatically prompt for branch name and create a new branch and worktree.
  3. Use "create branch", choose a name for the new branch, and then choose the "create branch in new worktree" option. It should show "create worktree for branch" option which creates a worktree for the new branch you just created, similar to scenario 1.
  4. Using "create worktree" on a remote branch should default to "new branch and worktree" option similar to case 2.

@sergeibbb
Copy link
Member

sergeibbb commented Sep 12, 2024

Hi @axosoft-ramint

Re testing scenario no-1. I'm not sure that I get it correctly. I see the same behavior in pre-release. It creates and opens a worktree without a question:

open-worktree-without-a-question.mp4

@axosoft-ramint
Copy link
Contributor Author

@sergeibbb in your screen share, you are using "Open in Worktree". These changes are for "Create Worktree" and should not affect the "Open in Worktree" flow.

@sergeibbb
Copy link
Member

sergeibbb commented Sep 12, 2024

@axosoft-ramint Same for create:

create-worktree-without-a-question.mp4

Re test scenario 2. I confirm that I see the difference:
image
the rest works as described.

@axosoft-ramint
Copy link
Contributor Author

axosoft-ramint commented Sep 12, 2024

@axosoft-ramint Same for create:

It looks to be functioning correctly, with expected behavior for scenario 1, based on your screenshare.

In the case of "create worktree" for a branch that is not already on a worktree, we now default to a single confirmation option, "create worktree for branch", rather than offering two options (the other being "create worktree for new branch named..."). The default option just creates a worktree for that branch, with its name, and then lets you choose how to open it.

In the case of "create worktree" for a branch that is already on one (i.e. scenario 2), we also have the same single confirmation option (create worktree for branch) which will let you choose a name for a new branch to create and will create a worktree on that new branch. It will function just like the "create worktree for new branch named..." option did before.

@sergeibbb
Copy link
Member

@axosoft-ramint
Ah! That's clear now. Thank you!

@sergeibbb
Copy link
Member

Re test scenario 3. Looks like no difference:

main:
image
image

feature:
image
image

@axosoft-ramint
Copy link
Contributor Author

Re test scenario 3. Looks like no difference:

@sergeibbb I apologize - my description of expected behavior in that scenario is completely wrong.

It should work like scenario 1 after using "Create branch in New Worktree". It should offer "Create Worktree for Branch" which just creates the worktree for the new branch you have created.

My apologies again - I will update the description of the steps. Thanks for testing it!

@sergeibbb
Copy link
Member

Re 4:

It does not create the local branch:

does-not-create-local-branch.mp4

@sergeibbb
Copy link
Member

@axosoft-ramint
Re 3.

It should work like scenario 1 after using "Create branch in New Worktree". It should offer "Create Worktree for Branch" which just creates the worktree for the new branch you have created.

Ah, I see. it has replaced "Create worktree for new branch named" with a "create worktree for branch". Now I see it. But it behaves identically. In both cases (main and feature branch) I come to the same result: a worktree for a new branch named after it.

@axosoft-ramint
Copy link
Contributor Author

axosoft-ramint commented Sep 12, 2024

@axosoft-ramint Re 3.

It should work like scenario 1 after using "Create branch in New Worktree". It should offer "Create Worktree for Branch" which just creates the worktree for the new branch you have created.

Ah, I see. it has replaced "Create worktree for new branch named" with a "create worktree for branch". Now I see it. But it behaves identically. In both cases (main and feature branch) I come to the same result: a worktree for a new branch named after it.

Yes, this one is mainly a naming change because the previous naming of the option for creating a worktree after creating the branch was confusing.

@axosoft-ramint
Copy link
Contributor Author

Re 4:

It does not create the local branch:

This looks like a bug. I will investigate. Thanks for catching it!

@axosoft-ramint
Copy link
Contributor Author

@sergeibbb I have fixed case 4 (and a separate bug with case 3 where it does not create the new branch). Would you mind testing all four cases once more?

Copy link
Member

@d13 d13 left a comment

Choose a reason for hiding this comment

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

LGTM

@sergeibbb
Copy link
Member

@axosoft-ramint

I confirm. #.4 fixed

@sergeibbb
Copy link
Member

sergeibbb commented Sep 12, 2024

@axosoft-ramint

re scenario 3
When I have several repos in my workspace, it falls to selecting a repository step:

image

and if I pick a wrong repo it behaves unpredictably, like asking about creating a branch again.

UPD. If I choose the repository correctly, it works. But, one more thing about it:
image

@sergeibbb
Copy link
Member

sergeibbb commented Sep 12, 2024

scenario 2 works well.
scenario 1 works well.

@axosoft-ramint
Copy link
Contributor Author

@axosoft-ramint

re scenario 3 When I have several repos in my workspace, it falls to selecting a repository step:

Good catch. This is an existing issue that this PR does not address, and we should write a follow-up ticket to fix it. Since it's not a new issue introduced by these changes, I will merge them for now.

@axosoft-ramint axosoft-ramint merged commit ccab2f2 into main Sep 12, 2024
2 checks passed
@axosoft-ramint axosoft-ramint deleted the feature/create-worktree-improvement branch September 12, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-worktrees Issues or features related to worktrees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Create Worktree" flow improvements

4 participants