chiark / gitweb /
dgit: checkout: New command.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Jul 2018 11:41:40 +0000 (12:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Jul 2018 00:59:22 +0000 (01:59 +0100)
Closes:#878443.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/changelog
dgit

index a45d6337af75101586cb7b2bd0016751fa99565d..62fb2bc72a2a1a56c40bebed8c403baede415ebe 100644 (file)
@@ -1,5 +1,8 @@
 dgit (5.7~) unstable; urgency=medium
 
+  New feature:
+  * dgit checkout: new subcommand.  Closes:#878443.
+
   Bugfixes:
   * dgit update-vcs-git: Honour --package properly.
 
diff --git a/dgit b/dgit
index c7336ddd84b7ea28f5a379ffb328948910059528..ca5737533847ee3d4d821fcf6eff7d2967e9b7bd 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -4643,6 +4643,40 @@ END
     pull();
 }
 
+sub cmd_checkout {
+    parseopts();
+    package_from_d_control();
+    @ARGV==1 or badusage "dgit checkout needs a suite argument";
+    ($isuite) = @ARGV;
+    notpushing();
+
+    foreach my $canon (qw(0 1)) {
+       if (!$canon) {
+           $csuite= $isuite;
+       } else {
+           undef $csuite;
+           canonicalise_suite();
+       }
+       if (length git_get_ref lref()) {
+           # local branch already exists, yay
+           last;
+       }
+       if (!length git_get_ref lrref()) {
+           if (!$canon) {
+               # nope
+               next;
+           }
+           dofetch();
+       }
+       # now lrref exists
+       runcmd (@git, qw(update-ref), lref(), lrref(), '');
+       last;
+    }
+    local $ENV{GIT_REFLOG_ACTION} = git_reflog_action_msg
+        "dgit checkout $isuite";
+    runcmd (@git, qw(checkout), lref());
+}
+
 sub cmd_update_vcs_git () {
     my $specsuite;
     if (@ARGV==0 || $ARGV[0] =~ m/^-/) {