chiark / gitweb /
d4c9a7e9751c691abf4165e909c85fdb22b9b0d1
[topbloke.git] / tb-create.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Getopt::Long;
7 use Topbloke;
8
9 Getopt::Long::Configure(qw(bundling));
10
11 die "bad usage\n" unless @ARGV==1;
12
13 our $spec = parse_branch_spec($ARGV[0]);
14 our $current = current_tb_branch();
15
16 die "cannot make branch starting at base of another;".
17     " check out a real branch\n" if $current->{Kind} eq 'base';
18
19 die "strange branch ref $current->{Kind} $current->{Ref},\n".
20     " making new branch with this as dep is unwise\n"
21     unless ($current->{Kind} eq 'foreign' ||
22             $current->{Kind} eq 'tip');
23
24 sub fillin ($$$) {
25     my ($key, $newval, $what) = @_;
26     return if defined $spec->{$key};
27     $spec->{$key} = $newval;
28 }
29
30 if (!defined $spec->{Email} || !defined $spec->{Domain}) {
31     my $eaddr = run_git_1line(qw(config user.email));
32     $eaddr =~ m/^(.*)\@/ or die "$eaddr ?";
33     fillin('Email',$1,'email domain');
34     fillin('Domain',$','email domain'); #');
35 }
36
37 if (!defined $spec->{Date}) {
38     $spec->{Date} = `LC_TIME=C date -u +%Y-%m-%dT%H%M%SZ`;
39     chomp $spec->{Date} or die $!;
40 }
41
42 length($spec->{Date})==18 or die "partial date specified, not supported\n";
43
44 my $newbranch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}";
45
46 $newbranch = run_git_1line(qw(check-ref-format --print), $newbranch);
47
48 printf "creating %s\n", $newbranch;