diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 40 |
1 files changed, 30 insertions, 10 deletions
@@ -862,18 +862,38 @@ class Project(object): | |||
862 | def AbandonBranch(self, name): | 862 | def AbandonBranch(self, name): |
863 | """Destroy a local topic branch. | 863 | """Destroy a local topic branch. |
864 | """ | 864 | """ |
865 | try: | 865 | rev = R_HEADS + name |
866 | tip_rev = self.bare_git.rev_parse(R_HEADS + name) | 866 | all = self.bare_ref.all |
867 | except GitError: | 867 | if rev not in all: |
868 | return | 868 | # Doesn't exist; assume already abandoned. |
869 | # | ||
870 | return True | ||
871 | |||
872 | head = self.work_git.GetHead() | ||
873 | if head == rev: | ||
874 | # We can't destroy the branch while we are sitting | ||
875 | # on it. Switch to a detached HEAD. | ||
876 | # | ||
877 | head = all[head] | ||
869 | 878 | ||
870 | if self.CurrentBranch == name: | 879 | rev = self.GetRemote(self.remote.name).ToLocal(self.revision) |
871 | self._Checkout( | 880 | if rev in all: |
872 | self.GetRemote(self.remote.name).ToLocal(self.revision), | 881 | revid = all[rev] |
873 | quiet=True) | 882 | elif IsId(rev): |
883 | revid = rev | ||
884 | else: | ||
885 | revid = None | ||
874 | 886 | ||
875 | cmd = ['branch', '-D', name] | 887 | if revid and head == revid: |
876 | GitCommand(self, cmd, capture_stdout=True).Wait() | 888 | _lwrite(os.path.join(self.worktree, '.git', HEAD), |
889 | '%s\n' % revid) | ||
890 | else: | ||
891 | self._Checkout(rev, quiet=True) | ||
892 | |||
893 | return GitCommand(self, | ||
894 | ['branch', '-D', name], | ||
895 | capture_stdout = True, | ||
896 | capture_stderr = True).Wait() == 0 | ||
877 | 897 | ||
878 | def PruneHeads(self): | 898 | def PruneHeads(self): |
879 | """Prune any topic branches already merged into upstream. | 899 | """Prune any topic branches already merged into upstream. |