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()
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')
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')
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')