Exemple #1
0
def test_track_branches():
    tmp_dir = mkdtemp()
    orig_dir = os.path.join(tmp_dir, 'orig')
    clone_dir = os.path.join(tmp_dir, 'clone')
    os.makedirs(orig_dir)
    os.makedirs(clone_dir)
    from subprocess import check_call, PIPE, check_output
    check_call('git init .', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('touch example.txt', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git commit -m "Init"', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch bloom', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch upstream', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch refactor', shell=True, cwd=orig_dir, stdout=PIPE)
    from vcstools import VcsClient
    clone = VcsClient('git', clone_dir)
    clone.checkout('file://{0}'.format(orig_dir), 'master')
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '* master\n'
    from bloom.git import track_branches
    track_branches(['bloom', 'upstream'], clone_dir)
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '  bloom\n* master\n  upstream\n'
    track_branches(cwd=clone_dir)
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '  bloom\n* master\n  refactor\n  upstream\n', \
           output + ' == `  bloom\n* master\n  refactor\n  upstream\n`'
    track_branches(['fake'], clone_dir)
    output = check_output('git branch', shell=True, cwd=clone_dir)
    assert output.count('fake') == 0
    rmtree(tmp_dir)
def checkout_distro_stack(distro_stack, from_url, spec):
    vcs_type = distro_stack.vcs_config.type
    tempdir = tempfile.mkdtemp()
    temp_repo = os.path.join(tempdir, distro_stack.name)
    client = VcsClient(vcs_type, temp_repo)
    client.checkout(from_url, spec)
    return temp_repo
def checkout_distro_stack(distro_stack, from_url, spec):
    vcs_type = distro_stack.vcs_config.type
    tempdir = tempfile.mkdtemp()
    temp_repo = os.path.join(tempdir, distro_stack.name)
    client = VcsClient(vcs_type, temp_repo)
    client.checkout(from_url, spec)
    return temp_repo
Exemple #4
0
def test_track_branches():
    tmp_dir = mkdtemp()
    orig_dir = os.path.join(tmp_dir, 'orig')
    clone_dir = os.path.join(tmp_dir, 'clone')
    os.makedirs(orig_dir)
    os.makedirs(clone_dir)
    from subprocess import check_call, PIPE, check_output
    check_call('git init .', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('touch example.txt', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git commit -m "Init"', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch bloom', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch upstream', shell=True, cwd=orig_dir, stdout=PIPE)
    check_call('git branch refactor', shell=True, cwd=orig_dir, stdout=PIPE)
    from vcstools import VcsClient
    clone = VcsClient('git', clone_dir)
    clone.checkout('file://{0}'.format(orig_dir), 'master')
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '* master\n'
    from bloom.git import track_branches
    track_branches(['bloom', 'upstream'], clone_dir)
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '  bloom\n* master\n  upstream\n'
    track_branches(cwd=clone_dir)
    output = check_output('git branch --no-color', shell=True, cwd=clone_dir)
    assert output == '  bloom\n* master\n  refactor\n  upstream\n', \
           output + ' == `  bloom\n* master\n  refactor\n  upstream\n`'
    track_branches(['fake'], clone_dir)
    output = check_output('git branch', shell=True, cwd=clone_dir)
    assert output.count('fake') == 0
    rmtree(tmp_dir)
def test_fuerte_package_repository(directory=None):
    """
    Release a single catkin stack (fuerte) repository.
    """
    directory = directory if directory is not None else os.getcwd()
    # Setup
    upstream_url = create_upstream_catkin_fuerte_repository('foo', directory)
    release_url = create_release_repo(upstream_url, 'git', 'fuerte_devel')
    release_dir = os.path.join(directory, 'foo_release_clone')
    release_client = VcsClient('git', release_dir)
    release_client.checkout(release_url)
    with change_directory(release_dir):
        ###
        ### Import upstream
        ###
        user('git-bloom-import-upstream --quiet')
        # does the upstream branch exist?
        assert branch_exists('upstream', local_only=True), "no upstream branch"
        # does the upstrea/0.1.0 tag exist?
        ret, out, err = user('git tag', return_io=True)
        assert out.count('upstream/0.1.0') == 1, "no upstream tag created"
        # Is the package.xml from upstream in the upstream branch now?
        with inbranch('upstream'):
            assert os.path.exists('stack.xml'), \
                   "upstream did not import: '" + os.getcwd() + "': " + \
                   str(os.listdir(os.getcwd()))
            assert open('stack.xml').read().count('0.1.0'), "not right file"

        ###
        ### Release generator
        ###
        with bloom_answer(bloom_answer.ASSERT_NO_QUESTION):
            ret = user('git-bloom-generate -y release -s upstream --quiet')
        # patch import should have reported OK
        assert ret == code.OK, "actually returned ({0})".format(ret)
        # do the proper branches exist?
        assert branch_exists('release/foo'), "no release/foo branch: " + \
                                             str(get_branches())
        assert branch_exists('patches/release/foo'), \
               "no patches/release/foo branch"
        # was the release tag created?
        ret, out, err = user('git tag', return_io=True)
        assert out.count('release/foo/0.1.0') == 1, "no release tag created"

        ###
        ### Release generator, again
        ###
        with bloom_answer(bloom_answer.ASSERT_NO_QUESTION):
            ret = user('git-bloom-generate -y release -s upstream --quiet')
        # patch import should have reported OK
        assert ret == code.OK, "actually returned ({0})".format(ret)
        # do the proper branches exist?
        assert branch_exists('release/foo'), "no release/foo branch: " + \
                                             str(get_branches())
        assert branch_exists('patches/release/foo'), \
               "no patches/release/foo branch"
        # was the release tag created?
        ret, out, err = user('git tag', return_io=True)
        assert out.count('release/foo/0.1.0') == 1, "no release tag created"
Exemple #6
0
def auto_upstream_checkout(upstream_repo, upstream_url, devel_branch):
    info("Searching in upstream development branch for the name and version")
    info("  Upstream url: " + upstream_url)
    info("  Upstream type: " + upstream_repo.get_vcs_type_name())
    if devel_branch:
        info("  Upstream branch: " + str(devel_branch))
    # Handle special svn cases
    if upstream_repo.get_vcs_type_name() == 'svn':
        if devel_branch == '':
            upstream_url += '/trunk'
        else:
            upstream_url += '/branches/' + str(devel_branch)
        devel_branch = ''
    # Checkout to the upstream development branch
    retcode = try_vcstools_checkout(upstream_repo, upstream_url, devel_branch)
    if retcode != 0:
        return retcode
    # Look into the upstream devel branch for the version
    meta = get_upstream_meta(upstream_repo.get_path())
    if meta is None or None in meta.values():
        error("Failed to get the upstream meta data.")
        return 1
    # Summarize the package.xml/stack.xml contents
    info("Found upstream with version: " + ansi('boldon') + meta['version'] + \
         ansi('reset'))
    if meta['type'] == 'stack.xml':
        info("Upstream contains a stack called: " + ansi('boldon') + \
             meta['name'][0] + ansi('reset'))
    else:
        info("Upstream contains package" + \
             ('s: ' if len(meta['name']) > 1 else ': ') + ansi('boldon') + \
             ', '.join(meta['name']) + ansi('reset'))
    # If svn recreate upstream_repo and checkout to the tag
    if upstream_repo.get_vcs_type_name() == 'svn':
        # Remove the /trunk from the url
        upstream_url = '/'.join(upstream_url.split('/')[:-1])
        upstream_dir = upstream_repo.get_path()
        shutil.rmtree(upstream_dir)  # Delete old upstream
        upstream_repo = VcsClient('svn', upstream_dir)
        checkout_url = upstream_url + '/tags/' + meta['version']
        if not upstream_repo.checkout(checkout_url):
            got_it = False
            for name in meta['name']:
                warning("Didn't find the tagged version at " + checkout_url)
                checkout_url = upstream_url + '/tags/' + name + \
                               '-' + meta['version']
                warning("Trying " + checkout_url)
                if upstream_repo.checkout(checkout_url):
                    got_it = True
                    break
            if not got_it:
                error("Could not checkout upstream version")
                return 1
    # Return the meta data
    return meta
Exemple #7
0
def main(sysargs=None):
    # Parse the commandline arguments
    parser = get_argument_parser()
    parser = add_global_arguments(parser)
    args = parser.parse_args(sysargs)
    handle_global_arguments(args)

    # Ensure we are in a git repository
    if execute_command('git status') != 0:
        parser.print_help()
        bailout("This is not a valid git repository.")

    # Track all the branches
    track_branches()

    if execute_command('git show-ref refs/heads/bloom') != 0:
        bailout("This does not appear to be a bloom release repo. "
                "Please initialize it first using:\n\n"
                "  git bloom-set-upstream <UPSTREAM_VCS_URL> <VCS_TYPE> "
                "[<VCS_BRANCH>]")

    current_branch = get_current_branch()
    bloom_repo = VcsClient('git', os.getcwd())
    result = 0
    try:
        # update rosdep is needed
        if args.do_not_update_rosdep:
            info("Updating rosdep")
            rosdep2.catkin_support.update_rosdep()
        # do it
        result = execute_bloom_generate_debian(args, bloom_repo)
    finally:
        if current_branch:
            execute_command('git checkout ' + current_branch)
    return result
Exemple #8
0
def test_get_current_branch():
    # Create a temporary workfolder
    tmp_dir = mkdtemp()
    from subprocess import check_call, PIPE
    # Create a test repo
    check_call('git init .', shell=True, cwd=tmp_dir, stdout=PIPE)

    from bloom.git import get_current_branch
    assert get_current_branch(tmp_dir) == None, \
           get_current_branch(tmp_dir) + ' == None'

    # Make a commit
    check_call('touch example.txt', shell=True, cwd=tmp_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=tmp_dir, stdout=PIPE)
    check_call('git commit -a -m "Initial commit."',
               shell=True,
               cwd=tmp_dir,
               stdout=PIPE)
    # Make a branch
    check_call('git branch bloom', shell=True, cwd=tmp_dir, stdout=PIPE)

    assert get_current_branch(tmp_dir) == 'master'

    # Change to the bloom branch
    check_call('git checkout bloom',
               shell=True,
               cwd=tmp_dir,
               stdout=PIPE,
               stderr=PIPE)

    assert get_current_branch(tmp_dir) == 'bloom'

    from vcstools import VcsClient
    client = VcsClient('git', tmp_dir)
    spec = client.get_version('master')
    check_call('git checkout {0}'.format(spec),
               shell=True,
               cwd=tmp_dir,
               stdout=PIPE,
               stderr=PIPE)

    assert get_current_branch(tmp_dir) == None, \
           get_current_branch(tmp_dir) + ' == None'

    rmtree(tmp_dir)
Exemple #9
0
    def test_set_upstream(self):
        # Initialize the git repo
        check_call("git init", shell=True, cwd=self.git_repo, stdout=PIPE)

        # Run the program and ok the initial commit option
        cmd = 'git-bloom-set-upstream https://github.com/ros/example.git git'
        p = Popen(cmd, shell=True, cwd=self.git_repo, stdin=PIPE, stdout=PIPE)
        p.communicate('y')
        assert p.returncode == 0

        # Ensure the proper branch was created by checking out to it
        client = VcsClient('git', self.git_repo)
        client.update('bloom')

        # Ensure the bloom.conf file exists and that it is correct
        bloom_conf_path = os.path.join(self.git_repo, 'bloom.conf')
        assert os.path.exists(bloom_conf_path)
        expected_contents = '[bloom]\n\tupstream = https://github.' \
                            'com/ros/example.git\n\tupstreamtype = git' \
                            '\n\tupstreambranch = \n'
        assert expected_contents == open(bloom_conf_path, 'r').read(), \
               open(bloom_conf_path, 'r').read()
Exemple #10
0
def test_get_current_branch():
    # Create a temporary workfolder
    tmp_dir = mkdtemp()
    from subprocess import check_call, PIPE
    # Create a test repo
    check_call('git init .', shell=True, cwd=tmp_dir, stdout=PIPE)

    from bloom.git import get_current_branch
    assert get_current_branch(tmp_dir) == None, \
           get_current_branch(tmp_dir) + ' == None'

    # Make a commit
    check_call('touch example.txt', shell=True, cwd=tmp_dir, stdout=PIPE)
    check_call('git add *', shell=True, cwd=tmp_dir, stdout=PIPE)
    check_call('git commit -a -m "Initial commit."', shell=True, cwd=tmp_dir,
               stdout=PIPE)
    # Make a branch
    check_call('git branch bloom', shell=True, cwd=tmp_dir, stdout=PIPE)

    assert get_current_branch(tmp_dir) == 'master'

    # Change to the bloom branch
    check_call('git checkout bloom', shell=True, cwd=tmp_dir, stdout=PIPE,
                stderr=PIPE)

    assert get_current_branch(tmp_dir) == 'bloom'

    from vcstools import VcsClient
    client = VcsClient('git', tmp_dir)
    spec = client.get_version('master')
    check_call('git checkout {0}'.format(spec), shell=True, cwd=tmp_dir,
               stdout=PIPE, stderr=PIPE)

    assert get_current_branch(tmp_dir) == None, \
           get_current_branch(tmp_dir) + ' == None'

    rmtree(tmp_dir)
Exemple #11
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'])

    # Check for a bloom branch
    check_for_bloom(os.getcwd())

    # Parse the bloom config file
    upstream_repo, upstream_type, upstream_branch = parse_bloom_conf()

    # Summarize the config contents
    summarize_repo_info(upstream_repo, upstream_type, upstream_branch)

    # If the upstream repo is git, then assert some things about the repo
    if upstream_type == 'git':
        info("Verifying a couple of things about the upstream git repo...")
        # Ensure the upstream repo is not setup as a gbp
        assert_is_not_gbp_repo(upstream_repo)

    # Checkout upstream
    upstream_dir = os.path.join(tmp_dir, 'upstream')
    upstream_client = VcsClient(upstream_type, upstream_dir)
    if args.upstream_branch != None:
        ver = args.upstream_branch
        warning("Overriding the bloom.conf branch with {0}".format(ver))
    else:
        ver = upstream_branch if upstream_branch != '(No branch set)' else ''

    checkout_url = upstream_repo
    checkout_ver = ver

    # Handle svn
    if upstream_type == 'svn':
        if ver == '':
            checkout_url = upstream_repo + '/trunk'
        else:
            checkout_url = upstream_repo + '/branches/' + ver
        checkout_ver = ''
        debug("Checking out from url {0}".format(checkout_url))
    else:
        debug("Checking out branch "
              "({0}) from url {1}".format(checkout_ver, checkout_url))

    # XXX TODO: Need to validate if ver is valid for the upstream repo...
    # see: https://github.com/vcstools/vcstools/issues/4
    if not upstream_client.checkout(checkout_url, checkout_ver):
        if upstream_type == 'svn':
            error("Could not checkout upstream repostiory "
                  "({0})".format(checkout_url))
        else:
            error("Could not checkout upstream repostiory "
                  "({0})".format(checkout_url) +
                  " to branch ({0})".format(ver))
        return 1

    # Get upstream meta data
    meta = get_upstream_meta(upstream_dir)
    if meta is None or None in meta.values():
        print(meta)
        bailout("Failed to get the upstream meta data.")

    # Summarize the stack.xml contents
    info("Upstream has version " + ansi('boldon') + meta['version'] +
         ansi('reset'))
    if meta['type'] == 'stack.xml':
        info("Upstream contains a stack called " + ansi('boldon') +
             meta['name'][0] + ansi('reset'))
    else:
        info("Upstream contains package" \
           + ('s: ' if len(meta['name']) > 1 else ': ') \
           + ', '.join(meta['name']))

    # For convenience
    name = meta['name'][0] if type(meta['name']) == list else meta['name']
    version = 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)
    # Change upstream_client for svn
    export_version = version
    if upstream_type == 'svn':
        upstream_client = VcsClient('svn', os.path.join(tmp_dir, 'svn_tag'))
        checkout_url = upstream_repo + '/tags/' + version
        if not upstream_client.checkout(checkout_url):
            warning("Didn't find the tagged version at " + checkout_url)
            checkout_url = upstream_repo + '/tags/' + name + '-' + version
            warning("Trying " + checkout_url)
            if not upstream_client.checkout(checkout_url):
                error("Could not checkout upstream version")
                return 1
        export_version = ''
    if not upstream_client.export_repository(export_version, tarball_path):
        error("Failed to export upstream repository.")
        return 1

    # 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
        full_version_strict = StrictVersion(version)
        last_tag_version = '.'.join([gbp_major, gbp_minor, gbp_patch])
        last_tag_version_strict = StrictVersion(last_tag_version)
        if full_version_strict < last_tag_version_strict:
            warning("""\
Version discrepancy:
The upstream version, {0}, should be greater than the previous \
release version, {1}.

Upstream should re-release or you should fix the release repository.\
""".format(version, last_tag_version))
        if full_version_strict == last_tag_version_strict:
            if args.replace:
                # Remove the conflicting tag first
                warning("""\
Version discrepancy:
The upstream version, {0}, is equal to a previous import version. \
Removing conflicting tag before continuing because the '--replace' \
options was specified.\
""".format(version))
                execute_command('git tag -d {0}'.format(last_tag))
                execute_command('git push origin :refs/tags/'
                                '{0}'.format(last_tag))
            else:
                warning("""\
Version discrepancy:
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
    output = check_output('git branch', shell=True)
    if output.count('upstream') == 0:
        info(ansi('boldon') + "No upstream branch" + ansi('reset') \
            + "... creating an initial upstream branch.")
        create_initial_upstream_branch()

    # Go to the master branch
    bloom_repo.update('master')

    # Detect if git-import-orig is installed
    if not detect_git_import_orig():
        bailout("git-import-orig not detected, did you install "
                "git-buildpackage?")

    # Import the tarball
    cmd = 'git import-orig {0}'.format(tarball_path + '.tar.gz')
    if not args.interactive:
        cmd += ' --no-interactive'
    if not args.merge:
        cmd += ' --no-merge'
    try:
        if check_call(cmd, shell=True) != 0:
            bailout("git-import-orig failed '{0}'".format(cmd))
    except CalledProcessError:
        bailout("git-import-orig failed '{0}'".format(cmd))

    # Push changes back to the original bloom repo
    execute_command('git push --all -f')
    execute_command('git push --tags')
Exemple #12
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'])

    # Check for a bloom branch
    check_for_bloom(os.getcwd())

    # Parse the bloom config file
    upstream_repo, upstream_type, upstream_branch = parse_bloom_conf()

    # Summarize the config contents
    summarize_repo_info(upstream_repo, upstream_type, upstream_branch)

    # If the upstream repo is git, then assert some things about the repo
    if upstream_type == 'git':
        info("Verifying a couple of things about the upstream git repo...")
        # Ensure the upstream repo is not setup as a gbp
        assert_is_not_gbp_repo(upstream_repo)

    # Checkout upstream
    upstream_dir = os.path.join(tmp_dir, 'upstream')
    upstream_client = VcsClient(upstream_type, upstream_dir)
    if args.upstream_branch != None:
        ver = args.upstream_branch
        warning("Overriding the bloom.conf branch with {0}".format(ver))
    else:
        ver = upstream_branch if upstream_branch != '(No branch set)' else ''

    checkout_url = upstream_repo
    checkout_ver = ver

    # Handle svn
    if upstream_type == 'svn':
        if ver == '':
            checkout_url = upstream_repo + '/trunk'
        else:
            checkout_url = upstream_repo + '/branches/' + ver
        checkout_ver = ''
        debug("Checking out from url {0}".format(checkout_url))
    else:
        debug("Checking out branch "
          "({0}) from url {1}".format(checkout_ver, checkout_url))

    # XXX TODO: Need to validate if ver is valid for the upstream repo...
    # see: https://github.com/vcstools/vcstools/issues/4
    if not upstream_client.checkout(checkout_url, checkout_ver):
        if upstream_type == 'svn':
            error(
                "Could not checkout upstream repostiory "
                "({0})".format(checkout_url)
            )
        else:
            error(
                "Could not checkout upstream repostiory "
                "({0})".format(checkout_url)
              + " to branch ({0})".format(ver)
            )
        return 1

    # Get upstream meta data
    meta = get_upstream_meta(upstream_dir)
    if meta is None or None in meta.values():
        print(meta)
        bailout("Failed to get the upstream meta data.")

    # Summarize the stack.xml contents
    info("Upstream has version " + ansi('boldon')
        + meta['version'] + ansi('reset'))
    if meta['type'] == 'stack.xml':
        info("Upstream contains a stack called " + ansi('boldon')
           + meta['name'][0] + ansi('reset'))
    else:
        info("Upstream contains package" \
           + ('s: ' if len(meta['name']) > 1 else ': ') \
           + ', '.join(meta['name']))

    # For convenience
    name = meta['name'][0] if type(meta['name']) == list else meta['name']
    version = 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)
    # Change upstream_client for svn
    export_version = version
    if upstream_type == 'svn':
        upstream_client = VcsClient('svn', os.path.join(tmp_dir, 'svn_tag'))
        checkout_url = upstream_repo + '/tags/' + version
        if not upstream_client.checkout(checkout_url):
            warning("Didn't find the tagged version at " + checkout_url)
            checkout_url = upstream_repo + '/tags/' + name + '-' + version
            warning("Trying " + checkout_url)
            if not upstream_client.checkout(checkout_url):
                error("Could not checkout upstream version")
                return 1
        export_version = ''
    if not upstream_client.export_repository(export_version, tarball_path):
        error("Failed to export upstream repository.")
        return 1

    # 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
        full_version_strict = StrictVersion(version)
        last_tag_version = '.'.join([gbp_major, gbp_minor, gbp_patch])
        last_tag_version_strict = StrictVersion(last_tag_version)
        if full_version_strict < last_tag_version_strict:
            warning("""\
Version discrepancy:
The upstream version, {0}, should be greater than the previous \
release version, {1}.

Upstream should re-release or you should fix the release repository.\
""".format(version, last_tag_version))
        if full_version_strict == last_tag_version_strict:
            if args.replace:
                # Remove the conflicting tag first
                warning("""\
Version discrepancy:
The upstream version, {0}, is equal to a previous import version. \
Removing conflicting tag before continuing because the '--replace' \
options was specified.\
""".format(version))
                execute_command('git tag -d {0}'.format(last_tag))
                execute_command('git push origin :refs/tags/'
                                '{0}'.format(last_tag))
            else:
                warning("""\
Version discrepancy:
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
    output = check_output('git branch', shell=True)
    if output.count('upstream') == 0:
        info(ansi('boldon') + "No upstream branch" + ansi('reset') \
            + "... creating an initial upstream branch.")
        create_initial_upstream_branch()

    # Go to the master branch
    bloom_repo.update('master')

    # Detect if git-import-orig is installed
    if not detect_git_import_orig():
        bailout("git-import-orig not detected, did you install "
                "git-buildpackage?")

    # Import the tarball
    cmd = 'git import-orig {0}'.format(tarball_path + '.tar.gz')
    if not args.interactive:
        cmd += ' --no-interactive'
    if not args.merge:
        cmd += ' --no-merge'
    try:
        if check_call(cmd, shell=True) != 0:
            bailout("git-import-orig failed '{0}'".format(cmd))
    except CalledProcessError:
        bailout("git-import-orig failed '{0}'".format(cmd))

    # Push changes back to the original bloom repo
    execute_command('git push --all -f')
    execute_command('git push --tags')
Exemple #13
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')
def test_multi_package_repository(directory=None):
    """
    Release a multi package catkin (groovy) repository.
    """
    directory = directory if directory is not None else os.getcwd()
    # Setup
    pkgs = ['foo', 'bar', 'baz']
    upstream_url = create_upstream_catkin_groovy_repository(pkgs, directory)
    release_url = create_release_repo(upstream_url, 'git', 'groovy_devel')
    release_dir = os.path.join(directory, 'foo_release_clone')
    release_client = VcsClient('git', release_dir)
    release_client.checkout(release_url)
    with change_directory(release_dir):
        ###
        ### Import upstream
        ###
        user('git-bloom-import-upstream --quiet')
        # does the upstream branch exist?
        assert branch_exists('upstream', local_only=True), "no upstream branch"
        # does the upstrea/0.1.0 tag exist?
        ret, out, err = user('git tag', return_io=True)
        assert out.count('upstream/0.1.0') == 1, "no upstream tag created"
        # Is the package.xml from upstream in the upstream branch now?
        with inbranch('upstream'):
            for pkg in pkgs:
                with change_directory(pkg):
                    assert os.path.exists('package.xml'), \
                           "upstream did not import: " + os.listdir()
                    assert open('package.xml').read().count('0.1.0'), \
                           "not right file"

        ###
        ### Release generator
        ###
        with bloom_answer(bloom_answer.ASSERT_NO_QUESTION):
            ret = user('git-bloom-generate -y release -s upstream --quiet')
        # patch import should have reported OK
        assert ret == code.OK, "actually returned ({0})".format(ret)
        # Check the environment after the release generator
        ret, out, err = user('git tag', return_io=True)
        for pkg in pkgs:
            # Does the release/pkg branch exist?
            assert branch_exists('release/' + pkg), \
                   "no release/" + pkg + " branch"
            # Does the patches/release/pkg branch exist?
            assert branch_exists('patches/release/' + pkg), \
                   "no patches/release/" + pkg + " branch"
            # Did the release tag get created?
            assert out.count('release/' + pkg + '/0.1.0') == 1, \
                   "no release tag created for " + pkg
            # Is there a package.xml in the top level?
            with inbranch('release/' + pkg):
                assert os.path.exists('package.xml'), "release branch invalid"
                # Is it the correct package.xml for this pkg?
                package_xml = open('package.xml', 'r').read()
                assert package_xml.count('<name>' + pkg + '</name>'), \
                       "incorrect package.xml for " + str(pkg)

        # Make a patch
        with inbranch('release/' + pkgs[0]):
            user('echo "This is a change" >> README.md')
            user('git add README.md')
            user('git commit -m "added a readme"')

        ###
        ### Release generator, again
        ###
        with bloom_answer(bloom_answer.ASSERT_NO_QUESTION):
            ret = user('git-bloom-generate -y release -s upstream --quiet')
        # patch import should have reported OK
        assert ret == code.OK, "actually returned ({0})".format(ret)
        # Check the environment after the release generator
        ret, out, err = user('git tag', return_io=True)
        for pkg in pkgs:
            # Does the release/pkg branch exist?
            assert branch_exists('release/' + pkg), \
                   "no release/" + pkg + " branch"
            # Does the patches/release/pkg branch exist?
            assert branch_exists('patches/release/' + pkg), \
                   "no patches/release/" + pkg + " branch"
            # Did the release tag get created?
            assert out.count('release/' + pkg + '/0.1.0') == 1, \
                   "no release tag created for " + pkg
            # Is there a package.xml in the top level?
            with inbranch('release/' + pkg):
                assert os.path.exists('package.xml'), "release branch invalid"
                # Is it the correct package.xml for this pkg?
                package_xml = open('package.xml', 'r').read()
                assert package_xml.count('<name>' + pkg + '</name>'), \
                       "incorrect package.xml for " + str(pkg)

        ###
        ### ROSDebian Generator
        ###
        with bloom_answer(bloom_answer.ASSERT_NO_QUESTION):
            ret, out, err = user('git-bloom-generate -y rosdebian '
                                 '-p release groovy --quiet', return_io=True)
        expected = "Debian Distributions: ['oneiric', 'precise', 'quantal']"
        assert out.count(expected) > 0, "not using expected ubuntu distros"
        # generator should have reported OK
        assert ret == code.OK, "actually returned ({0})".format(ret)
        # Check the environment after the release generator
        ret, out, err = user('git tag', return_io=True)
        for pkg in pkgs:
            for distro in ['oneiric', 'precise', 'quantal']:
                # Does the debian/distro/pkg branch exist?
                assert branch_exists('debian/groovy/' + distro + '/' + pkg), \
                       "no release/" + pkg + " branch"
                # Does the patches/debian/distro/pkg branch exist?
                patches_branch = 'patches/debian/groovy/' + distro + '/' + pkg
                assert branch_exists(patches_branch), \
                       "no patches/release/" + pkg + " branch"
                # Did the debian tag get created?
                tag = 'debian/ros-groovy-' + pkg + '_0.1.0-0_' + distro
                assert out.count(tag) == 1, \
                   "no release tag created for '" + pkg + "': `" + out + "`"
            # Is there a package.xml in the top level?
            with inbranch('debian/groovy/' + distro + '/' + pkg):
                assert os.path.exists('package.xml'), "release branch invalid"
                # Is it the correct package.xml for this pkg?
                package_xml = open('package.xml', 'r').read()
                assert package_xml.count('<name>' + pkg + '</name>'), \
                       "incorrect package.xml for " + str(pkg)