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

Dialog in case of deleting not fully merged branch. #425

Open
wants to merge 2 commits into
base: python3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ def run(self):

def branch_done(self, result):
self.results = result.rstrip().split('\n')
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)

def process(self, command):
self.run_command(['git'] + command + [self.picked_branch], self.update_status)

def panel_done(self, picked):
if 0 > picked < len(self.results):
return
picked_branch = self.results[picked]
if picked_branch.startswith("*"):
self.panel("Can't process with current branch")
return
picked_branch = picked_branch.strip()
self.run_command(['git'] + self.command_to_run_after_branch + [picked_branch], self.update_status)
self.picked_branch = picked_branch.strip()

self.process(self.command_to_run_after_branch)

def update_status(self, result):
global branch
Expand All @@ -61,7 +65,32 @@ class GitMergeCommand(GitBranchCommand):


class GitDeleteBranchCommand(GitBranchCommand):
command_to_run_after_branch = ['branch', '-d']
command_to_run_after_branch = ['branch', '-D']
command_to_run_after_branch_force = ['branch', '-D']
command_is_branch_merged = ['branch', '--no-merged']

def _process(self, command):
# default process behaviour
super(GitDeleteBranchCommand, self).process(command)

def process(self, command):
def no_merged_branches(result):
if any(
branch for branch in result.split('\n')
if branch.strip() == self.picked_branch
):
self.quick_panel(
['Delete not fully merged branch', 'Cancel'],
self.force_delete,
)
else:
self._process(command)

self.run_command(['git'] + self.command_is_branch_merged, no_merged_branches)

def force_delete(self, picked):
if picked == 0:
self._process(self.command_to_run_after_branch_force)


class GitNewBranchCommand(GitWindowCommand):
Expand Down