summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py40
-rw-r--r--subcmds/abandon.py23
2 files changed, 51 insertions, 12 deletions
diff --git a/project.py b/project.py
index 029a80f4..3b9535eb 100644
--- a/project.py
+++ b/project.py
@@ -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.
diff --git a/subcmds/abandon.py b/subcmds/abandon.py
index 4f976d7b..8af61327 100644
--- a/subcmds/abandon.py
+++ b/subcmds/abandon.py
@@ -16,6 +16,7 @@
16import sys 16import sys
17from command import Command 17from command import Command
18from git_command import git 18from git_command import git
19from progress import Progress
19 20
20class Abandon(Command): 21class Abandon(Command):
21 common = True 22 common = True
@@ -38,5 +39,23 @@ It is equivalent to "git branch -D <branchname>".
38 print >>sys.stderr, "error: '%s' is not a valid name" % nb 39 print >>sys.stderr, "error: '%s' is not a valid name" % nb
39 sys.exit(1) 40 sys.exit(1)
40 41
41 for project in self.GetProjects(args[1:]): 42 nb = args[0]
42 project.AbandonBranch(nb) 43 err = []
44 all = self.GetProjects(args[1:])
45
46 pm = Progress('Abandon %s' % nb, len(all))
47 for project in all:
48 pm.update()
49 if not project.AbandonBranch(nb):
50 err.append(project)
51 pm.end()
52
53 if err:
54 if len(err) == len(all):
55 print >>sys.stderr, 'error: no project has branch %s' % nb
56 else:
57 for p in err:
58 print >>sys.stderr,\
59 "error: %s/: cannot abandon %s" \
60 % (p.relpath, nb)
61 sys.exit(1)