alexiszamanidis / vscode-git-worktrees

A VS Code extension that wraps git worktree operations for simplicity and productivity
https://marketplace.visualstudio.com/items?itemName=GitWorktrees.git-worktrees
MIT License
44 stars 5 forks source link

Incorrect handling of multi-part branches #13

Closed yrtimiD closed 1 year ago

yrtimiD commented 1 year ago

Worktrees for the multi-part branches, like 'projX/bugfix/123' can't be added.

looks like if you do not specify a branch in the git worktree add <folder> <branch> command - git assumes the last part of the folder as a branch name, and new worktree become connected to a wrong branch. The git branch --set-upstream-to... command should fix this, but something goes wrong. Anyway, looks like there is an easier solution: if you'll merge these commands:

const worktreeAddCommand = `git worktree add ${newWorktreePath}`;
await executeCommand(worktreeAddCommand);

const connectBranchCommand = `git branch --set-upstream-to=origin/${newBranch} ${newBranch}`;
await executeCommand(connectBranchCommand);

to a single one:

const worktreeAddCommand = `git worktree add ${newWorktreePath} ${newBranch}`;
await executeCommand(worktreeAddCommand);

Resulting worktree folder will be created with the proper branch and upstream.

alexiszamanidis commented 1 year ago

Hi @yrtimiD,

Good catch!

Thanks for the solution. I tested it and it seems to work.

The fix has been published!

I also changed the default value of vsCodeGitWorktrees.move.openNewVscodeWindow. I feel it is good not to lose your previous vscode instance(as default behavior). You will also be able to see the informational message about the creation of the new worktree.

yrtimiD commented 1 year ago

Great, thanks! BTW, as a suggestion, on open a new vscode with a new worktree - can you pass current opened workspace to it?

alexiszamanidis commented 1 year ago

Oh, I see.

So, you have created a workspace with your worktrees and when you create a new worktree you want to add it to the workspace instead of opening a new vscode instance. Am I right? If I am, I'm assuming that the vscode won't open/reload, but just add the project to the workspace.

How does that sound to you? I think it would be a great addition to the current implementation.

yrtimiD commented 1 year ago

let's move the "open vscode" offtopic to #15

yrtimiD commented 1 year ago

tested v1.0.19, works good now, thank you!