<arg><option>--repo-user=</option><option>[GIT|DEBIAN]</option></arg>
<arg><option>--repo-email=</option><option>[GIT|DEBIAN]</option></arg>
<arg><option>--[no-]aliases</option></arg>
+ <arg><option>--[no-]add-upstream-vcs</option></arg>
<arg choice="plain"><replaceable>repository</replaceable></arg>
<arg><replaceable>directory</replaceable></arg>
</cmdsynopsis>
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--[no-]add-upstream-vcs</option>
+ </term>
+ <listitem>
+ <para>
+ Whether to add the upstream git repository as additional remote. The repositor url is read from
+ <filename>debian/upstream/meta</filename>.
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><replaceable>repository</replaceable></term>
<listitem>
@type def_config_files: dict (type, path)
"""
defaults = {'abbrev': 7,
+ 'add-upstream-vcs': 'False',
'aliases': 'True',
'allow-unauthenticated': 'False',
'arch': '',
'urgency': 'medium',
}
help = {
+ 'add-upstream-vcs':
+ "Whether to add the upstream vcs as additional remote "
+ "default is '%(add-upstream-vcs)s'",
'aliases':
"Whether to expand gbp specific aliases like `salsa:`,"
"default is '%(aliases)s'",
import re
import sys
import os
+import yaml
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.deb.git import DebianGitRepository
from gbp.git import (GitRepository, GitRepositoryError)
return repo
+def add_upstream_vcs(repo):
+ upstream_info = os.path.join('debian', 'upstream', 'metadata')
+ if not os.path.exists(upstream_info):
+ gbp.log.warn("No upstream metadata, can't track upstream repo")
+ return
+
+ with open(upstream_info) as f:
+ metadata = yaml.safe_load(f)
+ url = metadata.get('Repository', None)
+
+ if url is None:
+ gbp.log.warn("No repository in metadata, can't track upstream repo")
+ return
+
+ gbp.log.info(f"Adding upstream vcs at {url} as additional remote")
+ repo.add_remote_repo('upstreamvcs', url, fetch=True)
+
+
def build_parser(name):
try:
parser = GbpOptionParser(command=os.path.basename(name), prefix='',
branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options")
cmd_group = GbpOptionGroup(parser, "external command options", "how and when to invoke hooks")
+ uvcs_group = GbpOptionGroup(parser, "upstream vcs options", "upstream vcs options")
parser.add_option_group(branch_group)
parser.add_option_group(cmd_group)
+ parser.add_option_group(uvcs_group)
branch_group.add_option("--all", action="store_true", dest="all", default=False,
help="track all branches, not only debian and upstream")
"default is '%(postclone)s'")
cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks")
+ uvcs_group.add_boolean_config_file_option(option_name="add-upstream-vcs", dest='add_upstream_vcs')
+
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
if options.defuse_gitattributes.is_on() or not repo_setup.check_gitattributes(repo, 'HEAD'):
repo_setup.setup_gitattributes(repo)
+ if options.add_upstream_vcs:
+ add_upstream_vcs(repo)
+
if postclone:
Hook('Postclone', options.postclone,
extra_env={'GBP_GIT_DIR': repo.git_dir},
"""Test that cloning from vcs-git urls works"""
dest = os.path.join(self._tmpdir,
'cloned_repo')
- ret = clone(['arg0', "vcsgit:libvirt-glib", dest])
+ ret = clone(['arg0', "--add-upstream-vcs", "vcsgit:libvirt-glib", dest])
self.assertEquals(ret, 0)
cloned = ComponentTestGitRepository(dest)
self._check_repo_state(cloned, 'debian/sid', ['debian/sid', 'upstream/latest'])
+ assert cloned.has_remote_repo("upstreamvcs")
+ assert 'upstreamvcs/master' in cloned.get_remote_branches()
@skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled")
def test_clone_vcsgit_fail(self):