From: Ian Jackson Date: Sat, 21 Jan 2012 01:02:40 +0000 (+0000) Subject: read HEAD ourselves as git-symbolic-ref does not in fact silently exit 1 if not symbolic X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topbloke.git;a=commitdiff_plain;h=5e27959c9cf017851d9483a8ec43ed45dabc9c19 read HEAD ourselves as git-symbolic-ref does not in fact silently exit 1 if not symbolic --- diff --git a/Topbloke.pm b/Topbloke.pm index 2ff8913..6e9d727 100644 --- a/Topbloke.pm +++ b/Topbloke.pm @@ -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 = ; 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, diff --git a/tg-create.pl b/tg-create.pl index c205110..d4c9a7e 100755 --- a/tg-create.pl +++ b/tg-create.pl @@ -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) = @_;