Example #1
0
def test_get_last_tag_by_date():
    from tempfile import mkdtemp
    tmp_dir = mkdtemp()
    git_dir = os.path.join(tmp_dir, 'repo')
    os.makedirs(git_dir)
    from subprocess import check_call, PIPE
    check_call('git init .', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('touch example.txt', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git commit -m "Init"', shell=True, cwd=git_dir, stdout=PIPE)
    from bloom.git import get_last_tag_by_date
    assert get_last_tag_by_date(git_dir) == ''
    check_call('git tag upstream/0.3.2', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.3', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.4', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.5', shell=True, cwd=git_dir, stdout=PIPE)
    assert get_last_tag_by_date(git_dir) == 'upstream/0.3.5'
    from shutil import rmtree
    rmtree(tmp_dir)
Example #2
0
def test_get_last_tag_by_date():
    from tempfile import mkdtemp
    tmp_dir = mkdtemp()
    git_dir = os.path.join(tmp_dir, 'repo')
    os.makedirs(git_dir)
    from subprocess import check_call, PIPE
    check_call('git init .', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('touch example.txt', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git commit -m "Init"', shell=True, cwd=git_dir, stdout=PIPE)
    from bloom.git import get_last_tag_by_date
    assert get_last_tag_by_date(git_dir) == ''
    check_call('git tag upstream/0.3.2', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.3', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.4', shell=True, cwd=git_dir, stdout=PIPE)
    check_call('git tag upstream/0.3.5', shell=True, cwd=git_dir, stdout=PIPE)
    assert get_last_tag_by_date(git_dir) == 'upstream/0.3.5'
    from shutil import rmtree
    rmtree(tmp_dir)
Example #3
0
def import_upstream(cwd, tmp_dir, args):
    # Ensure the bloom and upstream branches are tracked locally
    track_branches(['bloom', 'upstream'])

    # Create a clone of the bloom_repo to help isolate the activity
    bloom_repo_clone_dir = os.path.join(tmp_dir, 'bloom_clone')
    os.makedirs(bloom_repo_clone_dir)
    os.chdir(bloom_repo_clone_dir)
    bloom_repo = VcsClient('git', bloom_repo_clone_dir)
    bloom_repo.checkout('file://{0}'.format(cwd))

    # Ensure the bloom and upstream branches are tracked from the original
    track_branches(['bloom', 'upstream'])

    ### Fetch the upstream tag
    upstream_repo = None
    upstream_repo_dir = os.path.join(tmp_dir, 'upstream_repo')
    # If explicit svn url just export and git-import-orig
    if args.explicit_svn_url is not None:
        if args.upstream_version is None:
            error("'--explicit-svn-version' must be specified with "
                  "'--explicit-svn-url'")
            return 1
        info("Checking out upstream at version " + ansi('boldon') + \
             str(args.upstream_version) + ansi('reset') + \
             " from repository at " + ansi('boldon') + \
             str(args.explicit_svn_url) + ansi('reset'))
        upstream_repo = VcsClient('svn', upstream_repo_dir)
        retcode = try_vcstools_checkout(upstream_repo, args.explicit_svn_url)
        if retcode != 0:
            return retcode
        meta = {
            'name': None,
            'version': args.upstream_version,
            'type': 'manual'
        }
    # Else fetching from bloom configs
    else:
        # Check for a bloom branch
        check_for_bloom()
        # Parse the bloom config file
        upstream_url, upstream_type, upstream_branch = parse_bloom_conf()
        # If the upstream_tag is specified, don't search just fetch
        upstream_repo = VcsClient(upstream_type, upstream_repo_dir)
        if args.upstream_tag is not None:
            warning("Using specified upstream tag '" + args.upstream_tag + "'")
            if upstream_type == 'svn':
                upstream_url += '/tags/' + args.upstream_tag
                upstream_tag = ''
            else:
                upstream_tag = args.upstream_tag
            retcode = try_vcstools_checkout(upstream_repo,
                                            upstream_url,
                                            upstream_tag)
            if retcode != 0:
                return retcode
            meta = {
                'name': None,
                'version': args.upstream_tag,
                'type': 'manual'
            }
        # We have to search for the upstream tag
        else:
            if args.upstream_devel is not None:
                warning("Overriding the bloom.conf upstream branch with " + \
                        args.upstream_devel)
                devel_branch = args.upstream_devel
            else:
                devel_branch = upstream_branch
            meta = auto_upstream_checkout(upstream_repo,
                                             upstream_url, devel_branch)
            if type(meta) not in [dict] and meta != 0:
                return meta

    ### Export the repository
    version = args.upstream_version if args.upstream_version is not None \
                                    else meta['version']

    # Export the repository to a tar ball
    tarball_prefix = 'upstream-' + str(version)
    info('Exporting version {0}'.format(version))
    tarball_path = os.path.join(tmp_dir, tarball_prefix)
    if upstream_repo.get_vcs_type_name() == 'svn':
        upstream_repo.export_repository('', tarball_path)
    else:
        if args.upstream_tag is not None:
            upstream_repo.export_repository(args.upstream_tag, tarball_path)
        else:
            upstream_repo.export_repository(version, tarball_path)

    # Get the gbp version elements from either the last tag or the default
    last_tag = get_last_tag_by_date()
    if last_tag == '':
        gbp_major, gbp_minor, gbp_patch = segment_version(version)
    else:
        gbp_major, gbp_minor, gbp_patch = \
            get_versions_from_upstream_tag(last_tag)
        info("The latest upstream tag in the release repository is "
              + ansi('boldon') + last_tag + ansi('reset'))
        # Ensure the new version is greater than the last tag
        last_tag_version = '.'.join([gbp_major, gbp_minor, gbp_patch])
        if parse_version(version) < parse_version(last_tag_version):
            warning("""\
Version discrepancy:
    The upstream version, {0}, is not newer than the previous \
release version, {1}.
""".format(version, last_tag_version))
        if parse_version(version) <= parse_version(last_tag_version):
            if args.replace:
                if not gbp.has_replace():
                    error("The '--replace' flag is not supported on this "
                          "version of git-buildpackage.")
                    return 1
                # Remove the conflicting tag first
                warning("""\
The upstream version, {0}, is equal to or less than a previous \
import version.
    Removing conflicting tag before continuing \
because the '--replace' options was specified.\
""".format(version))
                execute_command('git tag -d {0}'.format('upstream/' + version))
                execute_command('git push origin :refs/tags/'
                                '{0}'.format('upstream/' + version))
            else:
                warning("""\
The upstream version, {0}, is equal to a previous import version. \
git-buildpackage will fail, if you want to replace the existing \
upstream import use the '--replace' option.\
""".format(version))

    # Look for upstream branch
    if not branch_exists('upstream', local_only=True):
        create_branch('upstream', orphaned=True, changeto=True)

    # Go to the bloom branch during import
    bloom_repo.update('bloom')

    # Detect if git-import-orig is installed
    tarball_path += '.tar.gz'
    if gbp.import_orig(tarball_path, args.interactive) != 0:
        return 1

    # Push changes back to the original bloom repo
    execute_command('git push --all -f')
    execute_command('git push --tags')