chiark / gitweb /
read HEAD ourselves as git-symbolic-ref does not in fact silently exit 1 if not symbolic
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Jan 2012 01:02:40 +0000 (01:02 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Jan 2012 01:02:40 +0000 (01:02 +0000)
Topbloke.pm
tg-create.pl

index 2ff8913708a2024feebc4a1c19b9467323c03769..6e9d7272b0d8259014511771bed50889576831e6 100644 (file)
@@ -36,15 +36,25 @@ sub run_git_1line {
     return $l;
 }
 
+sub git_dir () {
+    our $git_dir;
+    if (!defined $git_dir) {
+       $git_dir = run_git_1line(qw(rev-parse --git-dir));
+    }
+    return $git_dir;
+}
+
 sub current_tb_branch () {
-    my ($estatus,$ref) = 
-       run_git_1line({ ExitStatus=>1 }, qw(symbolic-ref HEAD));
-    if ($estatus == 256) {
+    open R, git_dir().'/HEAD' or die "open HEAD $!";
+    my $ref = <R>;  defined $ref or die $!;
+    close R;
+    chomp $ref or die;
+    if ($ref !~ s#^ref: ##) {
        return {
-           Kind => 'detached'
+           Kind => 'detached',
+           Ref => $ref,
        };
     }
-    die "$estatus ?" if $estatus;
     if ($ref =~ m#^refs/topbloke-(tip|base)s/([^/\@]*)\@([^/\@]*)/([^/]*)/#) {
        return {
            Kind => $1,
index c205110afc0f0289b17ecaf3d1dd83bfa6f46123..d4c9a7e9751c691abf4165e909c85fdb22b9b0d1 100755 (executable)
@@ -16,8 +16,10 @@ our $current = current_tb_branch();
 die "cannot make branch starting at base of another;".
     " check out a real branch\n" if $current->{Kind} eq 'base';
 
-die "strange branch ref, making new branch with this as dep is unwise\n"
-    if $current->{Kind} eq 'weird';
+die "strange branch ref $current->{Kind} $current->{Ref},\n".
+    " making new branch with this as dep is unwise\n"
+    unless ($current->{Kind} eq 'foreign' ||
+           $current->{Kind} eq 'tip');
 
 sub fillin ($$$) {
     my ($key, $newval, $what) = @_;