]> Dogcows Code - chaz/graphql-client/blob - maint/branch_solo.pl
add tests and many fixes
[chaz/graphql-client] / maint / branch_solo.pl
1 #!/usr/bin/env perl
2
3 # This script prepares the graphql script for standalone use and puts it in a new branch.
4
5 use strict;
6 use warnings;
7 use autodie;
8
9 use File::Copy;
10 use File::Path qw(make_path remove_tree);
11 use String::ShellQuote;
12
13 my $version = shift or die 'Need version';
14 my $distdir = shift or die 'Need distdir';
15
16 my $branch_name = 'solo';
17 my $script_name = 'graphql';
18
19 my $branch_oldref = '';
20 my $branch_oldref_origin = '';
21
22 open(my $fh, '-|', qw{git show-ref}, $branch_name);
23 while (my $line = <$fh>) {
24 chomp $line;
25 my ($hash, $ref) = split(/\s+/, $line);
26 $branch_oldref = $hash if $ref eq "refs/heads/$branch_name";
27 $branch_oldref_origin = $hash if $ref eq "refs/remotes/origin/$branch_name";
28 }
29 if ($branch_oldref_origin && $branch_oldref ne $branch_oldref_origin) {
30 # reset local branch
31 system(qw{git branch -f}, $branch_name, "origin/$branch_name");
32 $branch_oldref = $branch_oldref_origin
33 }
34
35 my $commit_msg = shell_quote("Release $version");
36
37 my $solodir = "solo_branch.$$";
38 make_path($solodir);
39
40 use Config;
41 system($Config{'perlpath'}, qw{maint/fatpack.pl --clean --dist}, $distdir);
42 move($script_name, "$solodir/$script_name");
43
44 copy("$distdir/README", "$solodir/README");
45
46 system(qw{git update-index --add}, glob("$solodir/*"));
47 my $tree_ref = `git write-tree --prefix=$solodir/`;
48 chomp $tree_ref;
49
50 system(qw{git reset});
51 remove_tree($solodir);
52
53 my $branch_oldref_safe = shell_quote($branch_oldref);
54 my $tree_ref_safe = shell_quote($tree_ref);
55 my $parent = $branch_oldref ? "-p $branch_oldref_safe" : '';
56 my $commit_ref = `git commit-tree -m $commit_msg $parent $tree_ref_safe`;
57 chomp $commit_ref;
58
59 system(qw(git branch -f), $branch_name, $commit_ref);
60 system(qw(git tag -a -m), "Version $version", "$branch_name-$version", $commit_ref);
61
This page took 0.033816 seconds and 4 git commands to generate.