Ejemplo n.º 1
0
    def testParseFetchSpec(self):
        testData = [([], []),
                    (['main'], [('+refs/heads/main:refs/heads/main',
                                 r'\+refs/heads/main:.*')]),
                    (['main/'], [('+refs/heads/main:refs/heads/main',
                                  r'\+refs/heads/main:.*')]),
                    (['+main'], [('+refs/heads/main:refs/heads/main',
                                  r'\+refs/heads/main:.*')]),
                    (['master'], [('+refs/heads/master:refs/heads/master',
                                   r'\+refs/heads/master:.*')]),
                    (['master/'], [('+refs/heads/master:refs/heads/master',
                                    r'\+refs/heads/master:.*')]),
                    (['+master'], [('+refs/heads/master:refs/heads/master',
                                    r'\+refs/heads/master:.*')]),
                    (['refs/heads/*'], [('+refs/heads/*:refs/heads/*',
                                         r'\+refs/heads/\*:.*')]),
                    (['foo/bar/*',
                      'baz'], [('+refs/heads/foo/bar/*:refs/heads/foo/bar/*',
                                r'\+refs/heads/foo/bar/\*:.*'),
                               ('+refs/heads/baz:refs/heads/baz',
                                r'\+refs/heads/baz:.*')]),
                    (['refs/foo/*:refs/bar/*'], [('+refs/foo/*:refs/bar/*',
                                                  r'\+refs/foo/\*:.*')])]

        mirror = git_cache.Mirror('test://phony.example.biz')
        for fetch_specs, expected in testData:
            mirror = git_cache.Mirror('test://phony.example.biz',
                                      refs=fetch_specs)
            self.assertEqual(mirror.fetch_specs, set(expected))
Ejemplo n.º 2
0
    def testPopulate(self):
        self.git(['init', '-q'])
        with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
            f.write('touched\n')
        self.git(['add', 'foo'])
        self.git(['commit', '-m', 'foo'])

        mirror = git_cache.Mirror(self.origin_dir)
        mirror.populate()
Ejemplo n.º 3
0
    def testPopulateResetFetchConfigEmptyFetchConfig(self):
        self.git(['init', '-q'])
        with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
            f.write('touched\n')
        self.git(['add', 'foo'])
        self.git(['commit', '-m', 'foo'])

        mirror = git_cache.Mirror(self.origin_dir)
        mirror.populate(reset_fetch_config=True)
Ejemplo n.º 4
0
def PopulateCache(git_url, shallow=False):
    # --shallow by default checks out 10000 revision, but for really large
    # repos like adobe ones, we want significantly less than 10000.
    depth = None
    if shallow and 'adobe' in git_url:
        depth = 10
    mirror = git_cache.Mirror(git_url, print_func=lambda *args: None)
    mirror.populate(depth=depth, shallow=shallow)
    return mirror.mirror_path
Ejemplo n.º 5
0
    def testPopulateFetchWithoutTags(self):
        self._makeGitRepoWithTag()

        # Ask to not include tags.
        mirror = git_cache.Mirror(self.origin_dir)
        mirror.populate(no_fetch_tags=True)

        cache_dir = os.path.join(self.cache_dir,
                                 mirror.UrlToCacheDir(self.origin_dir))
        self.assertFalse(os.path.exists(cache_dir + '/refs/tags/TAG'))
Ejemplo n.º 6
0
    def testPopulateFetchTagsByDefault(self):
        self._makeGitRepoWithTag()

        # Default behaviour includes tags.
        mirror = git_cache.Mirror(self.origin_dir)
        mirror.populate()

        cache_dir = os.path.join(self.cache_dir,
                                 mirror.UrlToCacheDir(self.origin_dir))
        self.assertTrue(os.path.exists(cache_dir + '/refs/tags/TAG'))
Ejemplo n.º 7
0
 def _GetMirror(self, url, options):
   """Get a git_cache.Mirror object for the argument url."""
   if not git_cache.Mirror.GetCachePath():
     return None
   mirror_kwargs = {
       'print_func': self.filter,
       'refs': []
   }
   if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
     mirror_kwargs['refs'].append('refs/branch-heads/*')
   if hasattr(options, 'with_tags') and options.with_tags:
     mirror_kwargs['refs'].append('refs/tags/*')
   return git_cache.Mirror(url, **mirror_kwargs)
def PopulateCache(git_url, shallow=False, print_fn=None):
    # --shallow by default checks out 10000 revision, but for really large
    # repos like adobe ones, we want significantly less than 10000.
    depth = None
    if shallow and 'adobe' in git_url:
        depth = 10
    mirror = git_cache.Mirror(git_url, print_func=print_fn)
    mirror.populate(depth=depth,
                    shallow=shallow,
                    bootstrap=True,
                    verbose=True,
                    ignore_lock=True)
    return mirror.mirror_path
Ejemplo n.º 9
0
 def testPruneRequired(self):
     self.git(['init', '-q'])
     with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
         f.write('touched\n')
     self.git(['checkout', '-b', 'foo'])
     self.git(['add', 'foo'])
     self.git(['commit', '-m', 'foo'])
     mirror = git_cache.Mirror(self.origin_dir)
     mirror.populate()
     self.git(['checkout', '-b', 'foo_tmp', 'foo'])
     self.git(['branch', '-D', 'foo'])
     self.git(['checkout', '-b', 'foo/bar', 'foo_tmp'])
     mirror.populate()
     self.assertNotIn(git_cache.GIT_CACHE_CORRUPT_MESSAGE,
                      sys.stdout.getvalue())
Ejemplo n.º 10
0
def update_bootstrap(repo):  # pragma: no cover
    orig_out = sys.stdout
    orig_err = sys.stderr
    sys.stderr = FakeFile()
    sys.stdout = FakeFile()
    try:
        mirror = git_cache.Mirror(repo)
        mirror.populate(verbose=False, shallow=False, bootstrap=False)
        if subprocess.check_output(['git', 'ls-remote', '--heads', '.'],
                                   cwd=mirror.mirror_path).strip():
            mirror.update_bootstrap()
        else:
            print >> orig_out, 'Not a real repo, skipped'
    finally:
        sys.stderr = orig_err
        sys.stdout = orig_out
  def testPopulateResetFetchConfig(self):
    self.git(['init', '-q'])
    with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
      f.write('touched\n')
    self.git(['add', 'foo'])
    self.git(['commit', '-m', 'foo'])

    mirror = git_cache.Mirror(self.origin_dir)
    mirror.populate()

    # Add a bad refspec to the cache's fetch config.
    cache_dir = os.path.join(
        self.cache_dir, mirror.UrlToCacheDir(self.origin_dir))
    self.git(['config', '--add', 'remote.origin.fetch',
              '+refs/heads/foo:refs/heads/foo'],
             cwd=cache_dir)

    mirror.populate(reset_fetch_config=True)
Ejemplo n.º 12
0
 def GetCacheMirror(self):
   if (getattr(self, 'cache_dir', None)):
     url, _ = gclient_utils.SplitUrlRevision(self.url)
     return git_cache.Mirror(url)
   return None