Package: lintian
Version: 2.5.77~bpo9+1
Severity: wishlist
Tags: patch

If a package uses gbp and a deban-branch is specified in d/gbp.conf, then
vcswatch should probably be checking that branch.  In #886334, it's pointed out
that vcswatch cannot use gbp.conf since that requires unpacked source.  So
here's a lintian check to warn on the mismatch.

Thanks,
Ross
>From 56cec96dbd4ddfcc9c1c25637d0c07ba16c22048 Mon Sep 17 00:00:00 2001
From: Ross Vandegrift <r...@kallisti.us>
Date: Sun, 15 Apr 2018 11:39:30 -0700
Subject: [PATCH] Warn about mismatches between git branches in gbp.conf &
 Vcs-Git

If d/gbp.conf exists and the buildpackage section specifies a
debian-branch, then Vcs-Git should match that branch.  This helps with the
issue described in #886334.
---
 checks/git-buildpackage.desc                       | 15 +++++
 checks/git-buildpackage.pm                         | 66 ++++++++++++++++++++++
 debian/control                                     |  1 +
 .../debian/debian/control.in                       | 20 +++++++
 .../debian/debian/gbp.conf                         |  2 +
 t/tests/gbp-vcs-git-branch-mismatch/desc           |  6 ++
 t/tests/gbp-vcs-git-branch-mismatch/tags           |  1 +
 .../gbp-vcs-git-no-branch/debian/debian/control.in | 20 +++++++
 .../gbp-vcs-git-no-branch/debian/debian/gbp.conf   |  2 +
 t/tests/gbp-vcs-git-no-branch/desc                 |  6 ++
 t/tests/gbp-vcs-git-no-branch/tags                 |  1 +
 11 files changed, 140 insertions(+)
 create mode 100644 checks/git-buildpackage.desc
 create mode 100644 checks/git-buildpackage.pm
 create mode 100644 t/tests/gbp-vcs-git-branch-mismatch/debian/debian/control.in
 create mode 100644 t/tests/gbp-vcs-git-branch-mismatch/debian/debian/gbp.conf
 create mode 100644 t/tests/gbp-vcs-git-branch-mismatch/desc
 create mode 100644 t/tests/gbp-vcs-git-branch-mismatch/tags
 create mode 100644 t/tests/gbp-vcs-git-no-branch/debian/debian/control.in
 create mode 100644 t/tests/gbp-vcs-git-no-branch/debian/debian/gbp.conf
 create mode 100644 t/tests/gbp-vcs-git-no-branch/desc
 create mode 100644 t/tests/gbp-vcs-git-no-branch/tags

diff --git a/checks/git-buildpackage.desc b/checks/git-buildpackage.desc
new file mode 100644
index 000000000..3d0d06973
--- /dev/null
+++ b/checks/git-buildpackage.desc
@@ -0,0 +1,15 @@
+Check-Script: git-buildpackage
+Author: Ross Vandegrift <r...@kallisti.us>
+Abbrev: gbp
+Type: source
+Needs-Info: unpacked
+Info: This script checks for issues in <tt>gbp.conf</tt>.
+
+Tag: mismatch-between-vcs-git-and-gbp-debian-branch
+Severity: normal
+Certainty: possible
+Info: This package includes a debian/gbp.conf file, and the
+ buildpackage section specifies a branch name.  However, Vcs-Git in
+ debian/control points to a different branch.  If this package is
+ built with git-buildpackage, this will confuse vcswatch.
+Ref: policy 5.6.26
diff --git a/checks/git-buildpackage.pm b/checks/git-buildpackage.pm
new file mode 100644
index 000000000..64d63e76a
--- /dev/null
+++ b/checks/git-buildpackage.pm
@@ -0,0 +1,66 @@
+# git-buildpackage -- lintian check script -*- perl -*-
+
+# Copyright (C) 2018 Ross Vandegrift
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, you can find it on the World Wide
+# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Lintian::git_buildpackage;
+use strict;
+use warnings;
+use autodie;
+
+use Lintian::Tags qw(tag);
+
+use Config::IniFiles;
+
+sub run {
+    my ($pkg_name, $pkg_type, $info, $pkg, $group) = @_;
+
+    # check for a gbp.conf with debian-branch set in the buildpackage section
+    my $gbp_conf = $info->index_resolved_path('debian/gbp.conf');
+    return if not $gbp_conf;
+
+    my $cfg = Config::IniFiles->new(-file => $gbp_conf->fs_path);
+    my $gbp_branch = $cfg->val('buildpackage', 'debian-branch');
+    return if not $gbp_branch;
+
+    # check for a branch in Vcs-Git
+    my $dcontrol = $info->index_resolved_path('debian/control');
+    return if not $dcontrol;
+
+    my $fd = $dcontrol->open;
+    while (my $line = <$fd>) {
+        if ($line =~ /^Vcs-Git: /) {
+            my (undef, $url, $dash_b, $dcontrol_branch) = split(/\s+/, $line);
+            if ($dash_b ne '-b' || $dcontrol_branch ne $gbp_branch) {
+                tag 'mismatch-between-vcs-git-and-gbp-debian-branch';
+            }
+            last;
+        }
+    }
+    close($fd);
+
+    return;
+}
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/debian/control b/debian/control
index 6ad081384..bd89d697b 100644
--- a/debian/control
+++ b/debian/control
@@ -91,6 +91,7 @@ Depends: binutils,
          libarchive-zip-perl,
          libclass-accessor-perl,
          libclone-perl,
+         libconfig-inifiles-perl,
          libdigest-sha-perl,
          libdpkg-perl,
          libemail-valid-perl,
diff --git a/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/control.in 
b/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/control.in
new file mode 100644
index 000000000..c7c46a217
--- /dev/null
+++ b/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/control.in
@@ -0,0 +1,20 @@
+Source: {$source}
+Priority: optional
+Section: libs
+Maintainer: {$author}
+Standards-Version: {$standards_version}
+Build-Depends: {$build_depends}
+Rules-Requires-Root: no
+Vcs-Git: https://example.com/gbp-vcs-git-mismatch.git -b debian/experimental
+
+Package: {$source}
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description}
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.  It may
+ be an empty package.
+ .
+ This package has a default Vcs-Git but specifies a branch in
+ gbp.conf.  Since this confuses vcwatch, lintian should detect it.
diff --git a/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/gbp.conf 
b/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/gbp.conf
new file mode 100644
index 000000000..7713cbea8
--- /dev/null
+++ b/t/tests/gbp-vcs-git-branch-mismatch/debian/debian/gbp.conf
@@ -0,0 +1,2 @@
+[buildpackage]
+debian-branch = debian/sid
diff --git a/t/tests/gbp-vcs-git-branch-mismatch/desc 
b/t/tests/gbp-vcs-git-branch-mismatch/desc
new file mode 100644
index 000000000..14c84d21b
--- /dev/null
+++ b/t/tests/gbp-vcs-git-branch-mismatch/desc
@@ -0,0 +1,6 @@
+Testname: gbp-vcs-git-branch-mismatch
+Version: 1.0
+Description: Ensure that gbp.conf's debian-branch matches Vcs-Git
+Test-For:
+ mismatch-between-vcs-git-and-gbp-debian-branch
+
diff --git a/t/tests/gbp-vcs-git-branch-mismatch/tags 
b/t/tests/gbp-vcs-git-branch-mismatch/tags
new file mode 100644
index 000000000..686c7a73b
--- /dev/null
+++ b/t/tests/gbp-vcs-git-branch-mismatch/tags
@@ -0,0 +1 @@
+W: gbp-vcs-git-branch-mismatch source: 
mismatch-between-vcs-git-and-gbp-debian-branch
diff --git a/t/tests/gbp-vcs-git-no-branch/debian/debian/control.in 
b/t/tests/gbp-vcs-git-no-branch/debian/debian/control.in
new file mode 100644
index 000000000..455019d0c
--- /dev/null
+++ b/t/tests/gbp-vcs-git-no-branch/debian/debian/control.in
@@ -0,0 +1,20 @@
+Source: {$source}
+Priority: optional
+Section: libs
+Maintainer: {$author}
+Standards-Version: {$standards_version}
+Build-Depends: {$build_depends}
+Rules-Requires-Root: no
+Vcs-Git: https://example.com/gbp-vcs-git-mismatch.git
+
+Package: {$source}
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description}
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.  It may
+ be an empty package.
+ .
+ This package has a default Vcs-Git but specifies a branch in
+ gbp.conf.  Since this confuses vcwatch, lintian should detect it.
diff --git a/t/tests/gbp-vcs-git-no-branch/debian/debian/gbp.conf 
b/t/tests/gbp-vcs-git-no-branch/debian/debian/gbp.conf
new file mode 100644
index 000000000..7713cbea8
--- /dev/null
+++ b/t/tests/gbp-vcs-git-no-branch/debian/debian/gbp.conf
@@ -0,0 +1,2 @@
+[buildpackage]
+debian-branch = debian/sid
diff --git a/t/tests/gbp-vcs-git-no-branch/desc 
b/t/tests/gbp-vcs-git-no-branch/desc
new file mode 100644
index 000000000..e65783e9f
--- /dev/null
+++ b/t/tests/gbp-vcs-git-no-branch/desc
@@ -0,0 +1,6 @@
+Testname: gbp-vcs-git-no-branch
+Version: 1.0
+Description: Detect when gbp.conf has a debian-branch but Vcs-Git does not
+Test-For:
+ mismatch-between-vcs-git-and-gbp-debian-branch
+
diff --git a/t/tests/gbp-vcs-git-no-branch/tags 
b/t/tests/gbp-vcs-git-no-branch/tags
new file mode 100644
index 000000000..07aa1c196
--- /dev/null
+++ b/t/tests/gbp-vcs-git-no-branch/tags
@@ -0,0 +1 @@
+W: gbp-vcs-git-no-branch source: mismatch-between-vcs-git-and-gbp-debian-branch
-- 
2.11.0

Reply via email to