mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Modify 'repo abandon' to be more like 'repo checkout' and 'repo start'
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
89e717d948
commit
552ac89929
40
project.py
40
project.py
@ -862,18 +862,38 @@ class Project(object):
|
|||||||
def AbandonBranch(self, name):
|
def AbandonBranch(self, name):
|
||||||
"""Destroy a local topic branch.
|
"""Destroy a local topic branch.
|
||||||
"""
|
"""
|
||||||
try:
|
rev = R_HEADS + name
|
||||||
tip_rev = self.bare_git.rev_parse(R_HEADS + name)
|
all = self.bare_ref.all
|
||||||
except GitError:
|
if rev not in all:
|
||||||
return
|
# Doesn't exist; assume already abandoned.
|
||||||
|
#
|
||||||
|
return True
|
||||||
|
|
||||||
if self.CurrentBranch == name:
|
head = self.work_git.GetHead()
|
||||||
self._Checkout(
|
if head == rev:
|
||||||
self.GetRemote(self.remote.name).ToLocal(self.revision),
|
# We can't destroy the branch while we are sitting
|
||||||
quiet=True)
|
# on it. Switch to a detached HEAD.
|
||||||
|
#
|
||||||
|
head = all[head]
|
||||||
|
|
||||||
cmd = ['branch', '-D', name]
|
rev = self.GetRemote(self.remote.name).ToLocal(self.revision)
|
||||||
GitCommand(self, cmd, capture_stdout=True).Wait()
|
if rev in all:
|
||||||
|
revid = all[rev]
|
||||||
|
elif IsId(rev):
|
||||||
|
revid = rev
|
||||||
|
else:
|
||||||
|
revid = None
|
||||||
|
|
||||||
|
if revid and head == revid:
|
||||||
|
_lwrite(os.path.join(self.worktree, '.git', HEAD),
|
||||||
|
'%s\n' % revid)
|
||||||
|
else:
|
||||||
|
self._Checkout(rev, quiet=True)
|
||||||
|
|
||||||
|
return GitCommand(self,
|
||||||
|
['branch', '-D', name],
|
||||||
|
capture_stdout = True,
|
||||||
|
capture_stderr = True).Wait() == 0
|
||||||
|
|
||||||
def PruneHeads(self):
|
def PruneHeads(self):
|
||||||
"""Prune any topic branches already merged into upstream.
|
"""Prune any topic branches already merged into upstream.
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from command import Command
|
from command import Command
|
||||||
from git_command import git
|
from git_command import git
|
||||||
|
from progress import Progress
|
||||||
|
|
||||||
class Abandon(Command):
|
class Abandon(Command):
|
||||||
common = True
|
common = True
|
||||||
@ -38,5 +39,23 @@ It is equivalent to "git branch -D <branchname>".
|
|||||||
print >>sys.stderr, "error: '%s' is not a valid name" % nb
|
print >>sys.stderr, "error: '%s' is not a valid name" % nb
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for project in self.GetProjects(args[1:]):
|
nb = args[0]
|
||||||
project.AbandonBranch(nb)
|
err = []
|
||||||
|
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)
|
||||||
|
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)
|
||||||
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user