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 88df4ef..809d0b9 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: $!";