Add 'repo sync -d' to detach projects from their current topic

The -d flag moves the project back to a detached HEAD state,
matching what is listed in the manifest.  This can be useful to
set a client to something stable (or at least well-known), such as
before a sequence of 'repo download' commands are used to get some
changes for testing.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2009-04-10 16:59:36 -07:00
parent 96fdcef9e3
commit 3e768c9dc7
2 changed files with 17 additions and 3 deletions

View File

@ -573,7 +573,7 @@ class Project(object):
for file in self.copyfiles: for file in self.copyfiles:
file._Copy() file._Copy()
def Sync_LocalHalf(self): def Sync_LocalHalf(self, detach_head=False):
"""Perform only the local IO portion of the sync process. """Perform only the local IO portion of the sync process.
Network access is not required. Network access is not required.
@ -594,7 +594,7 @@ class Project(object):
branch = self.CurrentBranch branch = self.CurrentBranch
if branch is None: if branch is None or detach_head:
# Currently on a detached HEAD. The user is assumed to # Currently on a detached HEAD. The user is assumed to
# not have any local modifications worth worrying about. # not have any local modifications worth worrying about.
# #

View File

@ -44,12 +44,21 @@ line. Projects can be specified either by name, or by a relative
or absolute path to the project's local directory. If no projects or absolute path to the project's local directory. If no projects
are specified, '%prog' will synchronize all projects listed in are specified, '%prog' will synchronize all projects listed in
the manifest. the manifest.
The -d/--detach option can be used to switch specified projects
back to the manifest revision. This option is especially helpful
if the project is currently on a topic branch, but the manifest
revision is temporarily needed.
""" """
def _Options(self, p): def _Options(self, p):
p.add_option('-n','--network-only', p.add_option('-n','--network-only',
dest='network_only', action='store_true', dest='network_only', action='store_true',
help="fetch only, don't update working tree") help="fetch only, don't update working tree")
p.add_option('-d','--detach',
dest='detach_head', action='store_true',
help='detach projects back to manifest revision')
p.add_option('--no-repo-verify', p.add_option('--no-repo-verify',
dest='no_repo_verify', action='store_true', dest='no_repo_verify', action='store_true',
help='do not verify repo source code') help='do not verify repo source code')
@ -68,6 +77,10 @@ the manifest.
return fetched return fetched
def Execute(self, opt, args): def Execute(self, opt, args):
if opt.network_only and opt.detach_head:
print >>sys.stderr, 'error: cannot combine -n and -d'
sys.exit(1)
rp = self.manifest.repoProject rp = self.manifest.repoProject
rp.PreSync() rp.PreSync()
@ -111,7 +124,8 @@ the manifest.
for project in all: for project in all:
if project.worktree: if project.worktree:
if not project.Sync_LocalHalf(): if not project.Sync_LocalHalf(
detach_head=opt.detach_head):
sys.exit(1) sys.exit(1)