mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Fixed repo abandon to give better messages.
The main fix is to give an error message if nothing was actually abandoned. See <http://crosbug.com/6041>. The secondary fix is to list projects where the abandon happened. This could be done in a separate CL or dropped altogether if requested. TEST=manual $ repo abandon dougabc; echo $? Abandon dougabc: 100% (127/127), done. Abandoned in 2 project(s): chromite src/platform/init 0 $ repo abandon dougabc; echo $? Abandon dougabc: 100% (127/127), done. error: no project has branch dougabc 1 $ repo abandon dougabc; echo $? Abandon dougabc: 100% (127/127), done. error: chromite/: cannot abandon dougabc 1 Change-Id: I79520cc3279291acadc1a24ca34a761e9de04ed4
This commit is contained in:
parent
4655e81a75
commit
dafb1d68d3
12
project.py
12
project.py
@ -1204,13 +1204,19 @@ class Project(object):
|
|||||||
|
|
||||||
def AbandonBranch(self, name):
|
def AbandonBranch(self, name):
|
||||||
"""Destroy a local topic branch.
|
"""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
|
rev = R_HEADS + name
|
||||||
all = self.bare_ref.all
|
all = self.bare_ref.all
|
||||||
if rev not in all:
|
if rev not in all:
|
||||||
# Doesn't exist; assume already abandoned.
|
# Doesn't exist
|
||||||
#
|
return None
|
||||||
return True
|
|
||||||
|
|
||||||
head = self.work_git.GetHead()
|
head = self.work_git.GetHead()
|
||||||
if head == rev:
|
if head == rev:
|
||||||
|
@ -41,21 +41,30 @@ It is equivalent to "git branch -D <branchname>".
|
|||||||
|
|
||||||
nb = args[0]
|
nb = args[0]
|
||||||
err = []
|
err = []
|
||||||
|
success = []
|
||||||
all = self.GetProjects(args[1:])
|
all = self.GetProjects(args[1:])
|
||||||
|
|
||||||
pm = Progress('Abandon %s' % nb, len(all))
|
pm = Progress('Abandon %s' % nb, len(all))
|
||||||
for project in all:
|
for project in all:
|
||||||
pm.update()
|
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()
|
pm.end()
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
if len(err) == len(all):
|
for p in err:
|
||||||
print >>sys.stderr, 'error: no project has branch %s' % nb
|
print >>sys.stderr,\
|
||||||
else:
|
"error: %s/: cannot abandon %s" \
|
||||||
for p in err:
|
% (p.relpath, nb)
|
||||||
print >>sys.stderr,\
|
|
||||||
"error: %s/: cannot abandon %s" \
|
|
||||||
% (p.relpath, nb)
|
|
||||||
sys.exit(1)
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user