... |
... |
@@ -91,7 +91,7 @@ GIT_MODULES = '.gitmodules' |
91
|
91
|
#
|
92
|
92
|
class GitMirror(SourceFetcher):
|
93
|
93
|
|
94
|
|
- def __init__(self, source, path, url, ref):
|
|
94
|
+ def __init__(self, source, path, url, ref, tracking=None):
|
95
|
95
|
|
96
|
96
|
super().__init__()
|
97
|
97
|
self.source = source
|
... |
... |
@@ -100,6 +100,7 @@ class GitMirror(SourceFetcher): |
100
|
100
|
self.ref = ref
|
101
|
101
|
self.mirror = os.path.join(source.get_mirror_directory(), utils.url_directory_name(url))
|
102
|
102
|
self.mark_download_url(url)
|
|
103
|
+ self.track = tracking
|
103
|
104
|
|
104
|
105
|
# Ensures that the mirror exists
|
105
|
106
|
def ensure(self, alias_override=None):
|
... |
... |
@@ -204,6 +205,10 @@ class GitMirror(SourceFetcher): |
204
|
205
|
fail="Failed to checkout git ref {}".format(self.ref),
|
205
|
206
|
cwd=fullpath)
|
206
|
207
|
|
|
208
|
+ # Check that the user specified ref / tracked ref exists in the track if provided
|
|
209
|
+ if self.track:
|
|
210
|
+ self.assert_ref_in_track(fullpath)
|
|
211
|
+
|
207
|
212
|
# Remove .git dir
|
208
|
213
|
shutil.rmtree(os.path.join(fullpath, ".git"))
|
209
|
214
|
|
... |
... |
@@ -287,6 +292,22 @@ class GitMirror(SourceFetcher): |
287
|
292
|
|
288
|
293
|
return None
|
289
|
294
|
|
|
295
|
+ # Assert that ref exists in track, if track has been specified.
|
|
296
|
+ def assert_ref_in_track(self,fullpath):
|
|
297
|
+ _, branch = self.source.check_output([self.source.host_git, 'branch', '--list', self.track,
|
|
298
|
+ '--contains', self.ref],
|
|
299
|
+ cwd=fullpath,)
|
|
300
|
+ if branch:
|
|
301
|
+ return True
|
|
302
|
+ else:
|
|
303
|
+ _, tag = self.source.check_output([self.source.host_git, 'tag', '--list', self.track,
|
|
304
|
+ '--contains', self.ref],
|
|
305
|
+ cwd=fullpath,)
|
|
306
|
+ if tag:
|
|
307
|
+ return True
|
|
308
|
+ raise SourceError("{}: expected ref '{}' was not found in given track '{}' for staged repository: '{}'"
|
|
309
|
+ .format(self.source, self.ref, self.track, self.url))
|
|
310
|
+
|
290
|
311
|
|
291
|
312
|
class GitSource(Source):
|
292
|
313
|
# pylint: disable=attribute-defined-outside-init
|
... |
... |
@@ -298,8 +319,8 @@ class GitSource(Source): |
298
|
319
|
self.node_validate(node, config_keys + Source.COMMON_CONFIG_KEYS)
|
299
|
320
|
|
300
|
321
|
self.original_url = self.node_get_member(node, str, 'url')
|
301
|
|
- self.mirror = GitMirror(self, '', self.original_url, ref)
|
302
|
322
|
self.tracking = self.node_get_member(node, str, 'track', None)
|
|
323
|
+ self.mirror = GitMirror(self, '', self.original_url, ref, self.tracking)
|
303
|
324
|
self.checkout_submodules = self.node_get_member(node, bool, 'checkout-submodules', True)
|
304
|
325
|
self.submodules = []
|
305
|
326
|
|