[Notes] [Git][BuildStream/buildstream][tpollard/483] plugins/git.py: Fail if ref is not in given track



Title: GitLab

Tom Pollard pushed to branch tpollard/483 at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • buildstream/plugins/sources/git.py
    ... ... @@ -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
    
    ... ... @@ -298,8 +322,8 @@ class GitSource(Source):
    298 322
             self.node_validate(node, config_keys + Source.COMMON_CONFIG_KEYS)
    
    299 323
     
    
    300 324
             self.original_url = self.node_get_member(node, str, 'url')
    
    301
    -        self.mirror = GitMirror(self, '', self.original_url, ref)
    
    302 325
             self.tracking = self.node_get_member(node, str, 'track', None)
    
    326
    +        self.mirror = GitMirror(self, '', self.original_url, ref)
    
    303 327
             self.checkout_submodules = self.node_get_member(node, bool, 'checkout-submodules', True)
    
    304 328
             self.submodules = []
    
    305 329
     
    
    ... ... @@ -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,10 @@ 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
    +            if not self.tracked:
    
    412
    +                self.mirror.init_workspace(directory, track=self.tracking)
    
    413
    +            else:
    
    414
    +                self.mirror.init_workspace(directory)
    
    385 415
                 for mirror in self.submodules:
    
    386 416
                     mirror.init_workspace(directory)
    
    387 417
     
    
    ... ... @@ -397,7 +427,10 @@ class GitSource(Source):
    397 427
             # Stage the main repo in the specified directory
    
    398 428
             #
    
    399 429
             with self.timed_activity("Staging {}".format(self.mirror.url), silent_nested=True):
    
    400
    -            self.mirror.stage(directory)
    
    430
    +            if not self.tracked:
    
    431
    +                self.mirror.stage(directory, track=self.tracking)
    
    432
    +            else:
    
    433
    +                self.mirror.stage(directory)
    
    401 434
                 for mirror in self.submodules:
    
    402 435
                     if mirror.path in self.submodule_checkout_overrides:
    
    403 436
                         checkout = self.submodule_checkout_overrides[mirror.path]
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]