Update project paths after sync.
After a repo sync, some of the project paths might need
to be removed. This changes maintains a list of project
paths from the previous sync operation and compares.
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 9c9a3b7..d431c02 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -16,12 +16,15 @@
from optparse import SUPPRESS_HELP
import os
import re
+import shutil
import subprocess
import sys
import time
from git_command import GIT
from project import HEAD
+from project import Project
+from project import RemoteSpec
from command import Command, MirrorSafeCommand
from error import RepoChangedException, GitError
from project import R_HEADS
@@ -117,6 +120,48 @@
pm.end()
return fetched
+ def UpdateProjectList(self):
+ new_project_paths = []
+ for project in self.manifest.projects.values():
+ new_project_paths.append(project.relpath)
+ file_name = 'project.list'
+ file_path = os.path.join(self.manifest.repodir, file_name)
+ old_project_paths = []
+
+ if os.path.exists(file_path):
+ fd = open(file_path, 'r')
+ try:
+ old_project_paths = fd.read().split('\n')
+ finally:
+ fd.close()
+ for path in old_project_paths:
+ if path not in new_project_paths:
+ project = Project(
+ manifest = self.manifest,
+ name = path,
+ remote = RemoteSpec('origin'),
+ gitdir = os.path.join(self.manifest.topdir,
+ path, '.git'),
+ worktree = os.path.join(self.manifest.topdir, path),
+ relpath = path,
+ revisionExpr = 'HEAD',
+ revisionId = None)
+ if project.IsDirty():
+ print >>sys.stderr, 'error: Cannot remove project "%s": \
+uncommitted changes are present' % project.relpath
+ print >>sys.stderr, ' commit changes, then run sync again'
+ return -1
+ else:
+ print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
+ shutil.rmtree(project.worktree)
+
+ fd = open(file_path, 'w')
+ try:
+ fd.write('\n'.join(new_project_paths))
+ finally:
+ fd.close()
+ return 0
+
def Execute(self, opt, args):
if opt.network_only and opt.detach_head:
print >>sys.stderr, 'error: cannot combine -n and -d'
@@ -164,6 +209,9 @@
missing.append(project)
self._Fetch(missing)
+ if self.UpdateProjectList():
+ sys.exit(1)
+
syncbuf = SyncBuffer(mp.config,
detach_head = opt.detach_head)
pm = Progress('Syncing work tree', len(all))