Control: tags -1 + patch

Ian Jackson writes ("Want  dgit setup-vcs-git"):
> Lots of people are changing their Vcs-Git fields.  It would be nice
> for dgit at least to have a way to update the vcs-git url.

Since I wanted this I implemented it right away.

Sean, would you care to comment on the name of the command and the
manpage ?  The way it isn't like other setup-* things (in that
setup-new-tree doesn't do it) is slightly awkward but maybe that
doesn't matter.

I don't want to make setup-new-tree depend on having a working
debian/control.

Ian.

>From e0187d47f26c124a93022a10e6ed20181c765f36 Mon Sep 17 00:00:00 2001
From: Ian Jackson <ijack...@chiark.greenend.org.uk>
Date: Thu, 21 Jun 2018 14:05:26 +0100
Subject: [PATCH] dgit: Provide `setup-vcs-git' subcommand

This is for creating and adjusting the vcs-git remote url.  Useful for
transition from alioth to salsa.  Closes:#902006.

Signed-off-by: Ian Jackson <ijack...@chiark.greenend.org.uk>
---
 debian/changelog |  3 +++
 dgit             | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 dgit.1           | 22 ++++++++++++++++++++++
 3 files changed, 73 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index df25a846..ecacdb56 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,9 @@ dgit (5.2~) unstable; urgency=medium
   * --overwrite now no longer crashes if there is nothing to overwrite
     (eg, when used with --new).  Instead, it is simply ignored, as it is
     ignored in situations where the push is fast forward.  Closes:#863576.
+  * Provide `setup-vcs-git' subcommand, for creating and adjusting the
+    vcs-git remote url.  Useful for transition from alioth to salsa.
+    Closes:#902006.
 
   test suite:
   * Use nproc(1) rather than Sys::CPU.  This is more portable and does not
diff --git a/dgit b/dgit
index 5a6b2b68..8c10b763 100755
--- a/dgit
+++ b/dgit
@@ -617,6 +617,7 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit.dsc-url-proto-ok.http'    => 'true',
               'dgit.dsc-url-proto-ok.https'   => 'true',
               'dgit.dsc-url-proto-ok.git'     => 'true',
+              'dgit.vcs-git.suites',          => 'sid', # ;-separated
               'dgit.default.dsc-url-proto-ok' => 'false',
               # old means "repo server accepts pushes with old dgit tags"
               # new means "repo server accepts pushes with new dgit tags"
@@ -4621,6 +4622,53 @@ END
     pull();
 }
 
+sub cmd_setup_vcs_git () {
+    my $specsuite;
+    if (@ARGV==0 || $ARGV[0] =~ m/^-/) {
+       ($specsuite,) = split /\;/, cfg 'dgit.vcs-git.suites';
+    } else {
+       ($specsuite) = (@ARGV);
+       shift @ARGV;
+    }
+    my $dofetch=1;
+    if (@ARGV) {
+       if ($ARGV[0] eq '-') {
+           $dofetch = 0;
+       } elsif ($ARGV[0] eq '-') {
+           shift;
+       }
+    }
+
+    my $sourcep = parsecontrol 'debian/control', 'debian/control';
+    $package = getfield $sourcep, 'Source';
+    my $ctrl;
+    if ($specsuite eq '.') {
+       $ctrl = $sourcep;
+    } else {
+       $isuite = $specsuite;
+       get_archive_dsc();
+       $ctrl = $dsc;
+    }
+    my $url = getfield $ctrl, 'Vcs-Git';
+
+    my @cmd;
+    my $orgurl = cfg 'remote.vcs-git.url', 'RETURN-UNDEF';
+    if (!defined $orgurl) {
+       print STDERR "setting up vcs-git: $url\n";
+       @cmd = (@git, qw(remote add vcs-git), $url);
+    } elsif ($orgurl eq $url) {
+       print STDERR "vcs git already configured: $url\n";
+    } else {
+       print STDERR "changing vcs-git url to: $url\n";
+       @cmd = (@git, qw(remote set-url vcs-git), $url);
+    }
+    runcmd_ordryrun_local @cmd;
+    if ($dofetch) {
+       print "fetching (@ARGV)\n";
+       runcmd_ordryrun_local @git, qw(fetch vcs-git), @ARGV;
+    }
+}
+
 sub prep_push () {
     parseopts();
     build_or_push_prep_early();
diff --git a/dgit.1 b/dgit.1
index 6ee22e82..2bf08d01 100644
--- a/dgit.1
+++ b/dgit.1
@@ -88,6 +88,7 @@ For your convenience, the
 remote will be set up from the package's Vcs-Git field, if there is
 one - but note that in the general case the history found there may be
 different to or even disjoint from dgit's view.
+(See also dgit setup-vcs-git.)
 .TP
 \fBdgit fetch\fR [\fIsuite\fP]
 Consults the archive and git-repos to update the git view of
@@ -139,6 +140,20 @@ push-source, or dgit push.
 Cleans the current working tree (according to the --clean= option in
 force).
 .TP
+\fBdgit setup-vcs-git\fR [\fIsuite\fP|\fB.\fR] [\fB--\fR] [\fIgit fetch 
options\fR]
+.TQ
+\fBdgit setup-vcs-git\fR [\fIsuite|\fP\fB.\fR] \fB-\fR
+Sets up, or fixes the url of, the vcs-git remote, and
+(unless \fB-\fR was specified)
+runs git fetch on it.
+
+By default, the Vcs-Git field of the .dsc from Debian sid is used,
+as that is probably most up to date.
+Another suite may be specified, or
+.B .
+to indicate that the Vcs-Git of the cwd's debian/control should
+be used instead.
+.TP
 .B dgit help
 Print a usage summary.
 .TP
@@ -246,6 +261,11 @@ and
 (but only does each thing if dgit is configured to do it automatically).
 You can use these in any git repository, not just ones used with
 the other dgit operations.
+Does
+.B not
+run
+.B setup-vcs-git
+(as that requires Debian packaging information).
 .TP
 .B dgit setup-useremail
 Set the working tree's user.name and user.email from the
@@ -1173,6 +1193,8 @@ or when pushing and
 .BI dgit.dsc-url-proto-ok.bad-syntax
 .TP
 .BI dgit.default.dsc-url-proto-ok
+.TP
+.BR dgit.vcs-git.suites " \fIsuite\fR[" ; ...]
 .SH ENVIRONMENT VARIABLES
 .TP
 .BR DGIT_SSH ", " GIT_SSH
-- 
2.11.0

Reply via email to