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