... |
... |
@@ -190,7 +190,7 @@ class GitMirror(SourceFetcher): |
190
|
190
|
cwd=self.mirror)
|
191
|
191
|
return output.rstrip('\n')
|
192
|
192
|
|
193
|
|
- def stage(self, directory):
|
|
193
|
+ def stage(self, directory, track=None):
|
194
|
194
|
fullpath = os.path.join(directory, self.path)
|
195
|
195
|
|
196
|
196
|
# Using --shared here avoids copying the objects into the checkout, in any
|
... |
... |
@@ -204,10 +204,14 @@ class GitMirror(SourceFetcher): |
204
|
204
|
fail="Failed to checkout git ref {}".format(self.ref),
|
205
|
205
|
cwd=fullpath)
|
206
|
206
|
|
|
207
|
+ # Check that the user specified ref exists in the track if provided & not already tracked
|
|
208
|
+ if track:
|
|
209
|
+ self.assert_ref_in_track(fullpath, track)
|
|
210
|
+
|
207
|
211
|
# Remove .git dir
|
208
|
212
|
shutil.rmtree(os.path.join(fullpath, ".git"))
|
209
|
213
|
|
210
|
|
- def init_workspace(self, directory):
|
|
214
|
+ def init_workspace(self, directory, track=None):
|
211
|
215
|
fullpath = os.path.join(directory, self.path)
|
212
|
216
|
url = self.source.translate_url(self.url)
|
213
|
217
|
|
... |
... |
@@ -223,6 +227,10 @@ class GitMirror(SourceFetcher): |
223
|
227
|
fail="Failed to checkout git ref {}".format(self.ref),
|
224
|
228
|
cwd=fullpath)
|
225
|
229
|
|
|
230
|
+ # Check that the user specified ref exists in the track if provided & not already tracked
|
|
231
|
+ if track:
|
|
232
|
+ self.assert_ref_in_track(fullpath, track)
|
|
233
|
+
|
226
|
234
|
# List the submodules (path/url tuples) present at the given ref of this repo
|
227
|
235
|
def submodule_list(self):
|
228
|
236
|
modules = "{}:{}".format(self.ref, GIT_MODULES)
|
... |
... |
@@ -287,6 +295,22 @@ class GitMirror(SourceFetcher): |
287
|
295
|
|
288
|
296
|
return None
|
289
|
297
|
|
|
298
|
+ # Assert that ref exists in track, if track has been specified.
|
|
299
|
+ def assert_ref_in_track(self, fullpath, track):
|
|
300
|
+ _, branch = self.source.check_output([self.source.host_git, 'branch', '--list', track,
|
|
301
|
+ '--contains', self.ref],
|
|
302
|
+ cwd=fullpath,)
|
|
303
|
+ if branch:
|
|
304
|
+ return True
|
|
305
|
+ else:
|
|
306
|
+ _, tag = self.source.check_output([self.source.host_git, 'tag', '--list', track,
|
|
307
|
+ '--contains', self.ref],
|
|
308
|
+ cwd=fullpath,)
|
|
309
|
+ if tag:
|
|
310
|
+ return True
|
|
311
|
+ raise SourceError("{}: expected ref '{}' was not found in given track '{}' for staged repository: '{}'"
|
|
312
|
+ .format(self.source, self.ref, track, self.url))
|
|
313
|
+
|
290
|
314
|
|
291
|
315
|
class GitSource(Source):
|
292
|
316
|
# pylint: disable=attribute-defined-outside-init
|
... |
... |
@@ -317,6 +341,7 @@ class GitSource(Source): |
317
|
341
|
self.submodule_checkout_overrides[path] = checkout
|
318
|
342
|
|
319
|
343
|
self.mark_download_url(self.original_url)
|
|
344
|
+ self.tracked = False
|
320
|
345
|
|
321
|
346
|
def preflight(self):
|
322
|
347
|
# Check if git is installed, get the binary at the same time
|
... |
... |
@@ -374,6 +399,8 @@ class GitSource(Source): |
374
|
399
|
# Update self.mirror.ref and node.ref from the self.tracking branch
|
375
|
400
|
ret = self.mirror.latest_commit(self.tracking)
|
376
|
401
|
|
|
402
|
+ # Set tracked attribute, parameter for if self.mirror.assert_ref_in_track is needed
|
|
403
|
+ self.tracked = True
|
377
|
404
|
return ret
|
378
|
405
|
|
379
|
406
|
def init_workspace(self, directory):
|
... |
... |
@@ -381,7 +408,7 @@ class GitSource(Source): |
381
|
408
|
self.refresh_submodules()
|
382
|
409
|
|
383
|
410
|
with self.timed_activity('Setting up workspace "{}"'.format(directory), silent_nested=True):
|
384
|
|
- self.mirror.init_workspace(directory)
|
|
411
|
+ self.mirror.init_workspace(directory, track=(self.tracking if not self.tracked else None))
|
385
|
412
|
for mirror in self.submodules:
|
386
|
413
|
mirror.init_workspace(directory)
|
387
|
414
|
|
... |
... |
@@ -397,7 +424,7 @@ class GitSource(Source): |
397
|
424
|
# Stage the main repo in the specified directory
|
398
|
425
|
#
|
399
|
426
|
with self.timed_activity("Staging {}".format(self.mirror.url), silent_nested=True):
|
400
|
|
- self.mirror.stage(directory)
|
|
427
|
+ self.mirror.stage(directory, track=(self.tracking if not self.tracked else None))
|
401
|
428
|
for mirror in self.submodules:
|
402
|
429
|
if mirror.path in self.submodule_checkout_overrides:
|
403
|
430
|
checkout = self.submodule_checkout_overrides[mirror.path]
|