diff --git a/project.py b/project.py index 9d98041f..7ba1b38a 100644 --- a/project.py +++ b/project.py @@ -1204,13 +1204,19 @@ class Project(object): def AbandonBranch(self, name): """Destroy a local topic branch. + + Args: + name: The name of the branch to abandon. + + Returns: + True if the abandon succeeded; False if it didn't; None if the branch + didn't exist. """ rev = R_HEADS + name all = self.bare_ref.all if rev not in all: - # Doesn't exist; assume already abandoned. - # - return True + # Doesn't exist + return None head = self.work_git.GetHead() if head == rev: diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 8af61327..42abb2ff 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -41,21 +41,30 @@ It is equivalent to "git branch -D ". nb = args[0] err = [] + success = [] all = self.GetProjects(args[1:]) pm = Progress('Abandon %s' % nb, len(all)) for project in all: pm.update() - if not project.AbandonBranch(nb): - err.append(project) + + status = project.AbandonBranch(nb) + if status is not None: + if status: + success.append(project) + else: + err.append(project) pm.end() if err: - if len(err) == len(all): - print >>sys.stderr, 'error: no project has branch %s' % nb - else: - for p in err: - print >>sys.stderr,\ - "error: %s/: cannot abandon %s" \ - % (p.relpath, nb) + for p in err: + print >>sys.stderr,\ + "error: %s/: cannot abandon %s" \ + % (p.relpath, nb) sys.exit(1) + elif not success: + print >>sys.stderr, 'error: no project has branch %s' % nb + sys.exit(1) + else: + print >>sys.stderr, 'Abandoned in %d project(s):\n %s' % ( + len(success), '\n '.join(p.relpath for p in success))