aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2022-08-02 09:45:30 +0200
committerGuido Günther <agx@sigxcpu.org>2022-08-02 10:24:58 +0200
commitf76f2004bb6cfab3133925d7bf970e785f053572 (patch)
tree4be407b9dd07e98639d3545898d1d5261c7ff38f
parent227726ed493648b65c9a93924271a71f1b4b3551 (diff)
clone: Allow to add automatically add upstream vcs
While "gbp import-orig" supports "--upstream-vcs" since some time to link to the upstream git history however setup of the upstream remoet repo so far was manual. To make this more automatic add "--add-upstream-vcs" to "gbp clone" (defaulting to False) and set up the upstreamvcs remote in case there's sufficient information in debian/upstream/metadata. Once added fetch from that remote initially.
-rw-r--r--debian/control2
-rw-r--r--docs/manpages/gbp-clone.xml11
-rw-r--r--gbp/config.py4
-rwxr-xr-xgbp/scripts/clone.py26
-rw-r--r--tests/component/deb/test_clone.py4
5 files changed, 46 insertions, 1 deletions
diff --git a/debian/control b/debian/control
index 255dc534..c5de80dc 100644
--- a/debian/control
+++ b/debian/control
@@ -23,6 +23,7 @@ Build-Depends:
python3-pkg-resources,
python3-rpm,
python3-setuptools,
+ python3-yaml,
xsltproc,
# For the testsuite
bzip2 <!nocheck>,
@@ -53,6 +54,7 @@ Depends: ${python3:Depends},
man-db,
python3-dateutil,
python3-pkg-resources,
+ python3-yaml,
sensible-utils,
Recommends: pristine-tar (>= 1.41),
cowbuilder | pbuilder | sbuild,
diff --git a/docs/manpages/gbp-clone.xml b/docs/manpages/gbp-clone.xml
index 484304db..042b3d21 100644
--- a/docs/manpages/gbp-clone.xml
+++ b/docs/manpages/gbp-clone.xml
@@ -34,6 +34,7 @@
<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>
@@ -177,6 +178,16 @@
</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>
<para>
diff --git a/gbp/config.py b/gbp/config.py
index e5a0abc7..0a5a35e4 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -108,6 +108,7 @@ class GbpOptionParser(OptionParser):
@type def_config_files: dict (type, path)
"""
defaults = {'abbrev': 7,
+ 'add-upstream-vcs': 'False',
'aliases': 'True',
'allow-unauthenticated': 'False',
'arch': '',
@@ -201,6 +202,9 @@ class GbpOptionParser(OptionParser):
'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'",
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index ae8bbc28..7e02f0e2 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -22,6 +22,7 @@
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)
@@ -102,6 +103,24 @@ def repo_to_url(repo):
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='',
@@ -112,8 +131,10 @@ def build_parser(name):
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")
@@ -129,6 +150,8 @@ def build_parser(name):
"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')
@@ -216,6 +239,9 @@ def main(argv):
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},
diff --git a/tests/component/deb/test_clone.py b/tests/component/deb/test_clone.py
index a0678df4..ada301cb 100644
--- a/tests/component/deb/test_clone.py
+++ b/tests/component/deb/test_clone.py
@@ -61,10 +61,12 @@ class TestClone(ComponentTestBase):
"""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):