chiark / gitweb /
Clarify error message for missing refs/remotes/dgit/dgit/<suite>.
[dgit.git] / dgit
diff --git a/dgit b/dgit
index ba5f1ba8295c6b8d176411eddf3599d3786ea73b..207b5d09b6898258608f096cdc205a56ea36641e 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -358,6 +358,23 @@ sub parsechangelog {
     return $c;
 }
 
+sub git_get_ref ($) {
+    my ($refname) = @_;
+    my $got = cmdoutput_errok @git, qw(show-ref --), $refname;
+    if (!defined $got) {
+       $?==256 or fail "git show-ref failed (status $?)";
+       print DEBUG "ref $refname= [show-ref exited 1]\n";
+       return '';
+    }
+    if ($got =~ m/^(\w+) \Q$refname\E$/m) {
+       print DEBUG "ref $refname=$1\n";
+       return $1;
+    } else {
+       print DEBUG "ref $refname= [no match]\n";
+       return '';
+    }
+}
+
 our %rmad;
 
 sub archive_query ($) {
@@ -724,22 +741,13 @@ sub fetch_from_archive () {
        print "no version available from the archive\n";
     }
 
-    my $lrref_fn = ".git/".lrref();
-    if (open H, $lrref_fn) {
-       $lastpush_hash = <H>;
-       chomp $lastpush_hash;
-       die "$lrref_fn $lastpush_hash ?" unless $lastpush_hash =~ m/^\w+$/;
-    } elsif ($! == &ENOENT) {
-       $lastpush_hash = '';
-    } else {
-       die "$lrref_fn $!";
-    }
+    $lastpush_hash = git_get_ref(lrref());
     print DEBUG "previous reference hash=$lastpush_hash\n";
     my $hash;
     if (defined $dsc_hash) {
-       fail "missing git history even though dsc has hash -".
-           " could not find commit $dsc_hash".
-           " (should be in ".access_giturl()."#".rrref().")"
+       fail "missing remote git history even though dsc has hash -".
+           " could not find ref ".lrref().
+           " (should have been fetched from ".access_giturl()."#".rrref().")"
            unless $lastpush_hash;
        $hash = $dsc_hash;
        ensure_we_have_orig();