Пример #1
0
    def test_clone_origin(self):
        git = self.git

        # Make the origin we're going to test the clone against
        # This is intentionally different from upstream so that
        # we can confirm that upstream is also setup properly.
        origin_user = '******'
        origin_basedir = os.path.join(self.base_temp_dir, origin_user)
        os.makedirs(origin_basedir)
        check_subprocess('git -C "{origin_dir}" clone "{upstream}"'.format(
            origin_dir=origin_basedir, upstream=self.git_dir))

        test_parent = os.path.join(self.base_temp_dir, 'test_clone_origin')
        os.makedirs(test_parent)

        test_dir = os.path.join(test_parent, TEST_REPO_NAME)
        origin_dir = os.path.join(origin_basedir, TEST_REPO_NAME)
        self.git.clone_repository_to_path(origin_dir,
                                          test_dir,
                                          upstream_url=self.git_dir)

        want_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN)
        have_tags = git.query_tag_commits(test_dir, TAG_VERSION_PATTERN)
        self.assertEquals(want_tags, have_tags)

        got = check_subprocess('git -C "{dir}" remote -v'.format(dir=test_dir))

        remote = git.ORIGIN_REMOTE_NAME
        decoy = os.path.join(git.options.scratch_dir, 'nebula_decoys',
                             os.path.basename(self.git_dir))
        # Upstream repo is configured for pulls, but not for pushes.
        self.assertEquals(
            '\n'.join([
                '{remote}\t{origin} (fetch)'.format(remote=remote,
                                                    origin=origin_dir),
                '{remote}\t{origin} (push)'.format(remote=remote,
                                                   origin=origin_dir),
                'origin\t{decoy} (fetch)'.format(decoy=decoy),
                'origin\t{decoy} (push)'.format(decoy=decoy),
                'upstream\t{upstream} (fetch)'.format(upstream=self.git_dir),
                'upstream\tdisabled (push)'
            ]), got)

        reference = git.determine_remote_git_repository(test_dir)
        self.assertEquals(
            RemoteGitRepository.make_from_url(
                origin_dir,
                upstream_ref=RemoteGitRepository.make_from_url(self.git_dir)),
            reference)
Пример #2
0
    def test_clone_upstream(self):
        git = self.git
        test_parent = os.path.join(self.base_temp_dir, 'test_clone_upstream')
        os.makedirs(test_parent)

        test_dir = os.path.join(test_parent, TEST_REPO_NAME)
        git.clone_repository_to_path(self.git_dir, test_dir)
        self.assertTrue(os.path.exists(os.path.join(test_dir, 'base_file')))

        want_tags = git.query_tag_commits(self.git_dir, TAG_VERSION_PATTERN)
        have_tags = git.query_tag_commits(test_dir, TAG_VERSION_PATTERN)
        self.assertEquals(want_tags, have_tags)

        got = check_subprocess('git -C "{dir}" remote -v'.format(dir=test_dir))
        # Disable pushes to the origni
        # No upstream since origin is upstream
        remote = git.ORIGIN_REMOTE_NAME
        decoy = os.path.join(git.options.scratch_dir, 'nebula_decoys',
                             os.path.basename(self.git_dir))
        self.assertEquals(
            '\n'.join([
                '{remote}\t{origin} (fetch)'.format(remote=remote,
                                                    origin=self.git_dir),
                '{remote}\tdisabled (push)'.format(remote=remote),
                'origin\t{decoy} (fetch)'.format(decoy=decoy),
                'origin\t{decoy} (push)'.format(decoy=decoy)
            ]), got)

        reference = git.determine_remote_git_repository(test_dir)
        self.assertEquals(RemoteGitRepository.make_from_url(self.git_dir),
                          reference)
Пример #3
0
    def setUpClass(cls):
        cls.git = GitRunner(make_default_options())
        cls.base_temp_dir = tempfile.mkdtemp(prefix='scm_test')
        origin_root = os.path.join(cls.base_temp_dir, 'origin_repos')

        repository_list = [
            RemoteGitRepository.make_from_url(url) for url in [
                os.path.join(origin_root, SCM_USER, 'RepoOne'),
                os.path.join(origin_root, SCM_USER, 'RepoTwo'),
                os.path.join(origin_root, TEST_USER, 'RepoTest')
            ]
        ]

        cls.TEST_SOURCE_REPOSITORIES = {
            repo.name: repo
            for repo in repository_list
        }

        for repo in repository_list:
            os.makedirs(repo.url)
            base_file = os.path.join(repo.url,
                                     '{name}-base.txt'.format(name=repo.name))
            unique_file = os.path.join(
                repo.url, '{name}-unique.txt'.format(name=repo.name))
            untagged_file = os.path.join(
                repo.url, '{name}-untagged.txt'.format(name=repo.name))

            logging.debug('Initializing repository %s', repo.url)
            git_prefix = 'git -C "{dir}" '.format(dir=repo.url)
            run_git = lambda cmd: git_prefix + cmd

            check_subprocess_sequence([
                # BASE_VERSION
                'touch "{file}"'.format(file=base_file),
                run_git(' init'),
                run_git(
                    'add "{file}"'.format(file=os.path.basename(base_file))),
                run_git('commit -a -m "feat(first): first commit"'),
                run_git('tag {base_version} HEAD'.format(
                    base_version=BASE_VERSION)),

                # Add Unique branch name per repo
                run_git('checkout -b {name}-branch'.format(name=repo.name)),
                'touch "{file}"'.format(file=unique_file),
                run_git(
                    'add "{file}"'.format(file=os.path.basename(unique_file))),
                run_git('commit -a -m "chore(uniq): unique commit"'),

                # Add a common branch name, but without a tag on HEAD
                run_git('checkout master'),
                run_git('checkout -b {branch}'.format(branch=UNTAGGED_BRANCH)),
                'touch "{file}"'.format(file=untagged_file),
                run_git('add "{file}"'.format(
                    file=os.path.basename(untagged_file))),
                run_git('commit -a -m "chore(uniq): untagged commit"'),
                run_git('checkout master')
            ])
Пример #4
0
  def _do_determine_source_repositories(self):
    """Implements RepositoryCommand interface."""
    options = self.options

    all_source_repos = dict(SPINNAKER_BOM_REPOSITORIES)
    all_source_repos.update(SPINNAKER_HALYARD_REPOSITORIES)

    if options.github_user in ('upstream', 'default'):
      source_repositories = all_source_repos
    else:
      github = 'https://github.com/{user}'.format(user=options.github_user)
      source_repositories = {
          name: RemoteGitRepository(name, '%s/%s' % (github, name), upstream)
          for name, upstream in all_source_repos.items()
      }

    return self.filter_repositories(source_repositories)
Пример #5
0
import re

from buildtool.command import (RepositoryCommandFactory,
                               RepositoryCommandProcessor)

from buildtool.git import (RemoteGitRepository, GitRunner)

from buildtool.source_code_manager import (SPINNAKER_RUNNABLE_REPOSITORIES)

from buildtool.util import (determine_logfile_path,
                            check_subprocesses_to_logfile)

# See BuildGceComponentImages class comment as to why these are "repositories"
ALL_IMAGE_REPOSITORIES = dict(SPINNAKER_RUNNABLE_REPOSITORIES)
ALL_IMAGE_REPOSITORIES.update({
    name: RemoteGitRepository.make_from_url('https://placeholder/' + name)
    for name in ['consul', 'redis', 'vault']
})


class BuildGceComponentImages(RepositoryCommandProcessor):
    """Builds GCE VM images for each of the runtime components.

  Although we are calling this a RepositoryCommandProcessor, it
  isnt really processing repositories. Some of the images we generate
  are not associated with github or repos at all (e.g. redis). However
  the RepositoryCommandProcessor is a useful abstraction for its ability
  to parallelize across the different subsystems so we're going to overload
  it and pretend we have repositories even though we'll never do anything
  with their urls.
Пример #6
0
def _new_google_git_repo(name):
    return RemoteGitRepository.make_from_url('https://github.com/google/%s' %
                                             name)
Пример #7
0
def __new_spinnaker_git_repo(name):
    return RemoteGitRepository.make_from_url(
        'https://github.com/spinnaker/%s' % name)