diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2009-06-01 21:10:33 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2009-06-02 11:00:53 -0700 |
commit | 4f2517ff1174cd485f0ac93705b0fa9348595f6f (patch) | |
tree | 3d1db8ebf482ca75e8d5d75a589d4b578659f8cb /subcmds/sync.py | |
parent | fe200eeb520e1b50c00d359ca9e138f6149ce0f2 (diff) | |
download | git-repo-4f2517ff1174cd485f0ac93705b0fa9348595f6f.tar.gz |
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.
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index 9c9a3b78..d431c02e 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -16,12 +16,15 @@ | |||
16 | from optparse import SUPPRESS_HELP | 16 | from optparse import SUPPRESS_HELP |
17 | import os | 17 | import os |
18 | import re | 18 | import re |
19 | import shutil | ||
19 | import subprocess | 20 | import subprocess |
20 | import sys | 21 | import sys |
21 | import time | 22 | import time |
22 | 23 | ||
23 | from git_command import GIT | 24 | from git_command import GIT |
24 | from project import HEAD | 25 | from project import HEAD |
26 | from project import Project | ||
27 | from project import RemoteSpec | ||
25 | from command import Command, MirrorSafeCommand | 28 | from command import Command, MirrorSafeCommand |
26 | from error import RepoChangedException, GitError | 29 | from error import RepoChangedException, GitError |
27 | from project import R_HEADS | 30 | from project import R_HEADS |
@@ -117,6 +120,48 @@ later is required to fix a server side protocol bug. | |||
117 | pm.end() | 120 | pm.end() |
118 | return fetched | 121 | return fetched |
119 | 122 | ||
123 | def UpdateProjectList(self): | ||
124 | new_project_paths = [] | ||
125 | for project in self.manifest.projects.values(): | ||
126 | new_project_paths.append(project.relpath) | ||
127 | file_name = 'project.list' | ||
128 | file_path = os.path.join(self.manifest.repodir, file_name) | ||
129 | old_project_paths = [] | ||
130 | |||
131 | if os.path.exists(file_path): | ||
132 | fd = open(file_path, 'r') | ||
133 | try: | ||
134 | old_project_paths = fd.read().split('\n') | ||
135 | finally: | ||
136 | fd.close() | ||
137 | for path in old_project_paths: | ||
138 | if path not in new_project_paths: | ||
139 | project = Project( | ||
140 | manifest = self.manifest, | ||
141 | name = path, | ||
142 | remote = RemoteSpec('origin'), | ||
143 | gitdir = os.path.join(self.manifest.topdir, | ||
144 | path, '.git'), | ||
145 | worktree = os.path.join(self.manifest.topdir, path), | ||
146 | relpath = path, | ||
147 | revisionExpr = 'HEAD', | ||
148 | revisionId = None) | ||
149 | if project.IsDirty(): | ||
150 | print >>sys.stderr, 'error: Cannot remove project "%s": \ | ||
151 | uncommitted changes are present' % project.relpath | ||
152 | print >>sys.stderr, ' commit changes, then run sync again' | ||
153 | return -1 | ||
154 | else: | ||
155 | print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree | ||
156 | shutil.rmtree(project.worktree) | ||
157 | |||
158 | fd = open(file_path, 'w') | ||
159 | try: | ||
160 | fd.write('\n'.join(new_project_paths)) | ||
161 | finally: | ||
162 | fd.close() | ||
163 | return 0 | ||
164 | |||
120 | def Execute(self, opt, args): | 165 | def Execute(self, opt, args): |
121 | if opt.network_only and opt.detach_head: | 166 | if opt.network_only and opt.detach_head: |
122 | print >>sys.stderr, 'error: cannot combine -n and -d' | 167 | print >>sys.stderr, 'error: cannot combine -n and -d' |
@@ -164,6 +209,9 @@ later is required to fix a server side protocol bug. | |||
164 | missing.append(project) | 209 | missing.append(project) |
165 | self._Fetch(missing) | 210 | self._Fetch(missing) |
166 | 211 | ||
212 | if self.UpdateProjectList(): | ||
213 | sys.exit(1) | ||
214 | |||
167 | syncbuf = SyncBuffer(mp.config, | 215 | syncbuf = SyncBuffer(mp.config, |
168 | detach_head = opt.detach_head) | 216 | detach_head = opt.detach_head) |
169 | pm = Progress('Syncing work tree', len(all)) | 217 | pm = Progress('Syncing work tree', len(all)) |