From abaa7f312f1b6c8d11d7c757fe909900ce5788b5 Mon Sep 17 00:00:00 2001 From: Kevin Degi Date: Wed, 12 Nov 2014 11:27:45 -0700 Subject: Add option to correct gitdir when syncing In some cases, a user may wish to continue with a sync even though it would require overwriting an existing git directory. This behavior is not safe as a default because it could result in the loss of some user data, but as an optional flag it allows the user more flexibility. To support this, add a --force-sync flag to the sync command that will attempt to overwrite the existing git dir if it is specified and the existing git dir points to the wrong obj dir. Change-Id: Ieddda8ad54e264a1eb4a9d54881dd6ebc8a03833 --- subcmds/sync.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index ec333ae7..a8074a40 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -119,6 +119,11 @@ credentials. The -f/--force-broken option can be used to proceed with syncing other projects if a project sync fails. +The --force-sync option can be used to overwrite existing git +directories if they have previously been linked to a different +object direcotry. WARNING: This may cause data to be lost since +refs may be removed when overwriting. + The --no-clone-bundle option disables any attempt to use $URL/clone.bundle to bootstrap a new Git repository from a resumeable bundle file on a content delivery network. This @@ -174,6 +179,11 @@ later is required to fix a server side protocol bug. p.add_option('-f', '--force-broken', dest='force_broken', action='store_true', help="continue sync even if a project fails to sync") + p.add_option('--force-sync', + dest='force_sync', action='store_true', + help="overwrite an existing git directory if it needs to " + "point to a different object directory. WARNING: this " + "may cause loss of data") p.add_option('-l', '--local-only', dest='local_only', action='store_true', help="only update working tree, don't fetch") @@ -281,6 +291,7 @@ later is required to fix a server side protocol bug. success = project.Sync_NetworkHalf( quiet=opt.quiet, current_branch_only=opt.current_branch_only, + force_sync=opt.force_sync, clone_bundle=not opt.no_clone_bundle, no_tags=opt.no_tags, archive=self.manifest.IsArchive, optimized_fetch=opt.optimized_fetch) @@ -696,7 +707,7 @@ later is required to fix a server side protocol bug. for project in all_projects: pm.update() if project.worktree: - project.Sync_LocalHalf(syncbuf) + project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) pm.end() print(file=sys.stderr) if not syncbuf.Finish(): -- cgit v1.2.3-54-g00ecf