Skip to content
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

Merged
merged 4 commits into from May 24, 2017
Merged

Add git delete branch command #25862

merged 4 commits into from May 24, 2017

Conversation

letmaik
Copy link
Member

@letmaik letmaik commented May 3, 2017

This implements #2558

vscode-delete-branch

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:

  • This only implements deleting regular branches, not the remote branches, nor tags. Should those cases be handled as well? I have the feeling that removing remote branches should be handled automatically by regular purges.
  • I'm excluding the currently checked out branch from the list of branches to delete. For that, I used const currentHead = this.model.HEAD && this.model.HEAD.name; and then filtering by ref.name !== currentHead. I'm not sure if this.model.HEAD is the right way to get the current branch.
  • I have const placeHolder = 'Select a branch to delete'; but saw that other strings for prompts use localize(...). However, in the git.checkout command there is also such a placeHolder constant which does not use localize so I wasn't sure here.
  • In git/src/model.ts there is that weird Operation 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.

@mention-bot
Copy link

@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.

@msftclas
Copy link

msftclas commented May 3, 2017

@letmaik,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@joaomoreno joaomoreno added this to the May 2017 milestone May 4, 2017
@joaomoreno joaomoreno self-requested a review May 4, 2017 07:51
@joaomoreno joaomoreno added the git GIT issues label May 4, 2017
Copy link
Member

@joaomoreno joaomoreno left a 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.

@@ -650,6 +650,11 @@ export class Repository {
await this.run(args);
}

async deleteBranch(name: string): Promise<void> {
const args = ['branch', '-d', name];
Copy link
Member

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.

return;
}

await model.deleteBranch(ref);
Copy link
Member

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:

image

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?.

@letmaik
Copy link
Member Author

letmaik commented May 6, 2017

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.
About your comment to use the full branch ref name, this doesn't actually work with git branch, it wants the branch name itself, the full ref errors out.

@letmaik
Copy link
Member Author

letmaik commented May 20, 2017

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:

  1. Extfs writeFileAndFlush:
    Error: timeout of 2000ms exceeded.

@joaomoreno
Copy link
Member

Awesome, thanks dude 🍻

Sorry for the delay

@joaomoreno joaomoreno merged commit d0bae42 into microsoft:master May 24, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
git GIT issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants