From 2cf3f09b7bfbb91b486a307c149d88b717bd2894 Mon Sep 17 00:00:00 2001 From: Kamil Kujawinski Date: Sat, 8 Aug 2015 19:21:45 +0200 Subject: [PATCH 1/2] Dialog in case of deleting not fully merged branch. User can force removal and cancel. --- repo.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/repo.py b/repo.py index 78b5d4bd..c643ae27 100644 --- a/repo.py +++ b/repo.py @@ -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 @@ -62,6 +66,22 @@ class GitMergeCommand(GitBranchCommand): class GitDeleteBranchCommand(GitBranchCommand): command_to_run_after_branch = ['branch', '-d'] + command_to_run_after_branch_force = ['branch', '-D'] + + def force_delete(self, picked): + if picked == 0: + self.process(self.command_to_run_after_branch_force) + + def update_status(self, result): + if 'error' in result: + if 'not fully merged' in result: + self.quick_panel( + ['Delete not fully merged branch', 'Cancel'], + self.force_delete, + ) + else: + self.panel(result) + return super(GitDeleteBranchCommand, self).update_status(result) class GitNewBranchCommand(GitWindowCommand): From feeaad5ac4b3bb474e531192e1c84f6e13f66f35 Mon Sep 17 00:00:00 2001 From: Kamil Kujawinski Date: Sat, 15 Aug 2015 12:06:29 +0200 Subject: [PATCH 2/2] recognising not merged branch based on git command instead of command output --- repo.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/repo.py b/repo.py index c643ae27..1c770260 100644 --- a/repo.py +++ b/repo.py @@ -65,23 +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 force_delete(self, picked): - if picked == 0: - self.process(self.command_to_run_after_branch_force) + def _process(self, command): + # default process behaviour + super(GitDeleteBranchCommand, self).process(command) - def update_status(self, result): - if 'error' in result: - if 'not fully merged' in result: + 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.panel(result) - return super(GitDeleteBranchCommand, self).update_status(result) + 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):