Package: git-buildpackage
Version: 0.9.22
Severity: wishlist
Tags: patch

Hello.

https://www.debian.org/doc/debian-policy/ch-controlfields.html#version-control-system-vcs-fields
allows the VCS-Git to specify a branch and a relative path inside a
given repository.

# gbp clone vcs-git:pcscada
gbp:error: Can't find any vcs-git URL for 'pcscada'

The attached patch fixes the branch selection.
It does not allow a relative path.
>From 4550aaeedec99f7f48c456b6eae9d759ccf7de42 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Sun, 8 May 2022 16:50:29 +0200
Subject: [PATCH 2/3] clone: add second allowed form for vcs-git protocol to
 manual page

---
 docs/manpages/gbp-clone.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/manpages/gbp-clone.xml b/docs/manpages/gbp-clone.xml
index 849d990a..aa385cd5 100644
--- a/docs/manpages/gbp-clone.xml
+++ b/docs/manpages/gbp-clone.xml
@@ -197,6 +197,7 @@
       Clone from the <emphasis>Git-Vcs</emphasis> URL of a package:
     </para>
     <screen>
+    &gbp-clone; vcs-git:libvirt
     &gbp-clone; vcsgit:libvirt</screen>
     <para>
       Clone a repository from salsa (Debian's code hosting):
-- 
2.30.2

>From ed04b5242adf466b2f141090840d5f4ed4cf62d4 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Sun, 8 May 2022 16:51:26 +0200
Subject: [PATCH 3/3] clone: handle -b optional branch specification in VCS-Git

---
 gbp/scripts/clone.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index d538cdfe..f799fc6d 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -46,10 +46,15 @@ def apt_showsrc(pkg):
 
 
 def vcs_git_url(pkg):
+    """
+    Content of the latest available VCS-Git field, as a str.
+    None          when the field is missing.
+    (url, branch) when the value specifies a branch with -b.
+    """
     repos = {}
 
     out = apt_showsrc(pkg)
-    vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P<repo>[^ ]+)$', re.I)
+    vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P<repo>[^ ]+)(\s*-b\s*(?P<branch>[^ ]+))?$', re.I)
     version_re = re.compile(r'Version:\s*(?P<version>.*)$', re.I)
     end_re = re.compile(r'\s*$')
 
@@ -58,6 +63,8 @@ def vcs_git_url(pkg):
         m = vcs_re.match(line)
         if m:
             repo = m.group('repo')
+            if m.group('branch'):
+                repo = (repo, m.group('branch'))
             continue
         m = version_re.match(line)
         if m:
@@ -85,6 +92,9 @@ def repo_to_url(repo):
     'https://salsa.debian.org/agx/git-buildpackage.git'
     >>> repo_to_url("github:agx/git-buildpackage")
     'https://github.com/agx/git-buildpackage.git'
+
+    None          when VCS-Git is required but missing.
+    (url, branch) when VCS-Git specifies a branch with -b.
     """
     parts = repo.split(":", 1)
     if len(parts) != 2:
@@ -167,6 +177,10 @@ def main(argv):
         source = repo_to_url(args[1])
         if not source:
             return 1
+        elif isinstance(source, tuple):
+            source, vcs_git_branch = source
+        else:
+            vcs_git_branch = None
 
     clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False)
     try:
@@ -187,6 +201,10 @@ def main(argv):
         postclone = options.postclone
         (options, args) = parse_args(argv)
 
+        if vcs_git_branch not in (None, options.debian_branch):
+            gbp.log.warn(f'VCS-Git: -b {vcs_git_branch} overrides --debian-branch={options.debian_branch}')
+            options.debian_branch = vcs_git_branch
+
         # Track all branches:
         if options.all:
             remotes = repo.get_remote_branches()
-- 
2.30.2

Reply via email to