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
Add git delete branch command #25862
Conversation
@letmaik, thanks for your PR! By analyzing the history of the files in this pull request, we identified @joaomoreno and @jrieken to be potential reviewers. |
@letmaik, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just needs a bit of error handling.
extensions/git/src/git.ts
Outdated
@@ -650,6 +650,11 @@ export class Repository { | |||
await this.run(args); | |||
} | |||
|
|||
async deleteBranch(name: string): Promise<void> { | |||
const args = ['branch', '-d', name]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should be explicit with the branch name and use its full form refs/heads/${name}
instead of simply name
.
extensions/git/src/commands.ts
Outdated
return; | ||
} | ||
|
||
await model.deleteBranch(ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A common error from this operation happens when the branch isn't yet merged:
It would be great if the underlying git library would catch this situation, wrap it neatly in a GitError
with a new GitErrorCode
and we try catch
it here, prompting the user Hey, the branch isn't yet merge. Do you still want to delete it?
.
I worked a bit more on it, let me know what you think. It comes up with a confirmation prompt now if the branch is not fully merged, and if the user confirms to proceed, then it does it again but with force. |
Do you want me to do anything else here? I checked the failing macOS build but I think this is just a random error in the tests and not related:
|
Awesome, thanks dude 🍻 Sorry for the delay |
This implements #2558
This is my first contribution, so the approach I took in implementing it is probably quite naive. I'm looking forward to comments and suggestions on how to improve the code. Some things I wasn't sure about:
const currentHead = this.model.HEAD && this.model.HEAD.name;
and then filtering byref.name !== currentHead
. I'm not sure ifthis.model.HEAD
is the right way to get the current branch.const placeHolder = 'Select a branch to delete';
but saw that other strings for prompts uselocalize(...)
. However, in thegit.checkout
command there is also such aplaceHolder
constant which does not uselocalize
so I wasn't sure here.git/src/model.ts
there is that weirdOperation
enum with bit shifting for the values. I haven't understood what the exact purpose of that is, so I just followed the pattern and added a new entry at the end.