Exemple #1
0
    def setUpClass(cls):
        cls.git = GitRunner(make_default_options())
        cls.base_temp_dir = tempfile.mkdtemp(prefix='git_test')
        cls.git_dir = os.path.join(cls.base_temp_dir, UPSTREAM_USER,
                                   TEST_REPO_NAME)
        os.makedirs(cls.git_dir)

        git_dir = cls.git_dir
        gitify = lambda args: 'git -C "{dir}" {args}'.format(dir=git_dir,
                                                             args=args)
        check_subprocess_sequence([
            gitify('init'), 'touch "{dir}/base_file"'.format(dir=git_dir),
            gitify('add "{dir}/base_file"'.format(dir=git_dir)),
            gitify('commit -a -m "feat(test): added file"'),
            gitify(
                'tag {base_version} HEAD'.format(base_version=VERSION_BASE)),
            gitify(
                'checkout -b {base_branch}'.format(base_branch=BRANCH_BASE)),
            gitify('checkout -b {a_branch}'.format(a_branch=BRANCH_A)),
            'touch "{dir}/a_file"'.format(dir=git_dir),
            gitify('add "{dir}/a_file"'.format(dir=git_dir)),
            gitify('commit -a -m "feat(test): added a_file"'),
            gitify('tag {a_version} HEAD'.format(a_version=VERSION_A)),
            gitify('checkout -b {b_branch}'.format(b_branch=BRANCH_B)),
            'touch "{dir}/b_file"'.format(dir=git_dir),
            gitify('add "{dir}/b_file"'.format(dir=git_dir)),
            gitify('commit -a -m "feat(test): added b_file"'),
            gitify('tag {b_version} HEAD'.format(b_version=VERSION_B))
        ])
Exemple #2
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')
            ])
Exemple #3
0
    def setUpClass(cls):
        cls.git = GitRunner(make_default_options())
        cls.base_temp_dir = tempfile.mkdtemp(prefix='git_test')
        cls.git_dir = os.path.join(cls.base_temp_dir, 'commit_message_test')
        os.makedirs(cls.git_dir)

        git_dir = cls.git_dir
        gitify = lambda args: 'git -C "{dir}" {args}'.format(dir=git_dir,
                                                             args=args)
        check_subprocess_sequence([
            gitify('init'), 'touch "{dir}/base_file"'.format(dir=git_dir),
            gitify('add "{dir}/base_file"'.format(dir=git_dir)),
            gitify('commit -a -m "feat(test): added file"'),
            gitify(
                'tag {base_version} HEAD'.format(base_version=VERSION_BASE)),
            gitify('checkout -b {patch_branch}'.format(
                patch_branch=cls.PATCH_BRANCH)),
            'touch "{dir}/patch_file"'.format(dir=git_dir),
            gitify('add "{dir}/patch_file"'.format(dir=git_dir)),
            gitify('commit -a -m "fix(testA): added patch_file"'),
            gitify('checkout -b {minor_branch}'.format(
                minor_branch=cls.MINOR_BRANCH)),
            'touch "{dir}/minor_file"'.format(dir=git_dir),
            gitify('add "{dir}/minor_file"'.format(dir=git_dir)),
            gitify('commit -a -m "chore(testB): added minor_file"'),
            gitify('checkout -b {major_branch}'.format(
                major_branch=cls.MAJOR_BRANCH)),
            'touch "{dir}/major_file"'.format(dir=git_dir),
            gitify('add "{dir}/major_file"'.format(dir=git_dir)),
            gitify('commit -a -m'
                   ' "feat(testC): added major_file\n'
                   '\nInterestingly enough, this is a BREAKING CHANGE.'
                   '"'),
            gitify('checkout -b {merged_branch}'.format(
                merged_branch=cls.MERGED_BRANCH)),
            gitify('reset --hard HEAD~3'),
            gitify('merge --squash HEAD@{1}')
        ])
        env = dict(os.environ)
        if os.path.exists('/bin/true'):
            env['EDITOR'] = '/bin/true'
        elif os.path.exists('/usr/bin/true'):
            env['EDITOR'] = '/usr/bin/true'
        else:
            raise NotImplementedError('platform not supported for this test')
        check_subprocess('git -C "{dir}" commit'.format(dir=git_dir), env=env)
Exemple #4
0
    def reinit_local_repository_with_tag(self, git_dir, git_tag,
                                         initial_commit_message):
        """Recreate the given local repository using the current content.

    The Netflix Nebula gradle plugin that spinnaker uses to build the sources
    is hardcoded with some incompatible constraints which we are unable to
    change (the owner is receptive but wont do it for us and we arent familiar
    with how it works or exactly what needs changed). Therefore we'll wipe out
    the old tags and just put the one tag we want in order to avoid ambiguity.
    We'll detatch the old repository to avoid accidental pushes. It's much
    faster to create a new repo than remove all the existing tags.

    Args:
      git_dir: [path]  The path to the local git repository.
         If this has an existing .git directory it will be removed.
         The directory will be re initialized as a new repository.
      git_tag: [string] The tag to give the initial commit
      initial_commit_message: [string] The initial commit message
        when commiting the existing directory content to the new repo.
    """
        if git_tag is None:
            git_tag = check_subprocess(
                'git -C "{dir}" describe --tags --abbrev=0'.format(
                    dir=git_dir))

        escaped_commit_message = initial_commit_message.replace('"', '\\"')
        logging.info('Removing old .git from %s and starting new at %s',
                     git_dir, git_tag)
        original_origin = self.determine_remote_git_repository(git_dir)

        shutil.rmtree(os.path.join(git_dir, '.git'))

        _git = 'git -C "{dir}" '.format(dir=git_dir)
        check_subprocess_sequence([
            _git + 'init', _git + 'add .',
            _git + 'remote add {name} {url}'.format(
                name='origin', url=original_origin.url), _git +
            'remote set-url --push {name} disabled'.format(name='origin'),
            _git + 'commit -q -a -m "{message}"'.format(
                message=escaped_commit_message),
            _git + 'tag {tag} HEAD'.format(tag=git_tag)
        ])