chiark / gitweb /
import-dsc: Refuse to update a checked-out branch
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Oct 2016 19:16:17 +0000 (20:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 30 Oct 2016 19:50:47 +0000 (19:50 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index 88df4ef5eedeaf0bca604e477067dc2b53d18b49..809d0b9d06fc713de3d6eb70ea689007576a0aed 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -5284,6 +5284,13 @@ sub cmd_import_dsc {
     $dstbranch = "refs/heads/$dstbranch" unless $dstbranch =~ m#^refs/#;
     $dstbranch = cmdoutput @git, qw(check-ref-format --normalize), $dstbranch;
 
+    my @symcmd = (@git, qw(symbolic-ref -q HEAD));
+    my $chead = cmdoutput_errok @symcmd;
+    defined $chead or $?==256 or failedcmd @symcmd;
+
+    fail "$dstbranch is checked out - will not update it"
+       if defined $chead and $chead eq $dstbranch;
+
     open D, "<", $dscfn or fail "open import .dsc ($dscfn): $!";
     $dscdata = do { local $/ = undef; <D>; };
     D->error and fail "read $dscfn: $!";