Fix switching manifest branches using repo init -b

See repo issue #46 :
	https://code.google.com/p/git-repo/issues/detail?id=46

When using repo init -b on an already existing repository,
the next sync will try to rebase changes coming from the old manifest
branch onto the new, leading in the best case scenario to conflicts
and in the worst case scenario to an incorrect "mixed up" manifest.

This patch fixes this by deleting the "default" branch in the local
manifest repository when the -d init switch is used, thus forcing
repo to perform a fresh checkout of the new manifest branch

Change-Id: I379e4875ec5357d8614d1197b6afbe58f9606751
This commit is contained in:
Florian Vallee 2012-06-07 17:19:26 +02:00 committed by Shawn O. Pearce
parent 475a47d531
commit 5d016502eb
2 changed files with 19 additions and 0 deletions

View File

@ -2167,6 +2167,22 @@ class MetaProject(Project):
self.revisionExpr = base self.revisionExpr = base
self.revisionId = None self.revisionId = None
def MetaBranchSwitch(self, target):
""" Prepare MetaProject for manifest branch switch
"""
# detach and delete manifest branch, allowing a new
# branch to take over
syncbuf = SyncBuffer(self.config, detach_head = True)
self.Sync_LocalHalf(syncbuf)
syncbuf.Finish()
return GitCommand(self,
['branch', '-D', 'default'],
capture_stdout = True,
capture_stderr = True).Wait() == 0
@property @property
def LastFetch(self): def LastFetch(self):
try: try:

View File

@ -187,6 +187,9 @@ to update the working directory files.
shutil.rmtree(m.gitdir) shutil.rmtree(m.gitdir)
sys.exit(1) sys.exit(1)
if opt.manifest_branch:
m.MetaBranchSwitch(opt.manifest_branch)
syncbuf = SyncBuffer(m.config) syncbuf = SyncBuffer(m.config)
m.Sync_LocalHalf(syncbuf) m.Sync_LocalHalf(syncbuf)
syncbuf.Finish() syncbuf.Finish()