Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Created January 19, 2016 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2shortplanks/2e34e74298127c3c3208 to your computer and use it in GitHub Desktop.
Save 2shortplanks/2e34e74298127c3c3208 to your computer and use it in GitHub Desktop.
MAIN SCRIPT:
#!/usr/bin/perl
use strict;
use warnings;
use File::Temp qw(tempfile);
my $commit = shift or die "You have to pass a commit";
# read in the log message
my $log;
{
my @program = ('git','log','--format=%B','-n',1,$commit);
my $program = join ' ', @program;
open my $pfh, "-|", @program
or die "Can't run '$program': $!";
$log = do { local $/ = undef; <$pfh> };
close $pfh
or die "Can't close program '$program': $!";
}
# git rebase!
{
local $ENV{EDITOR} = '/Users/mark/bin/picky';
system("git","rebase","-i","${commit}^")
== 0 or die "Can't rebase!";
}
system("git reset HEAD~") == 0 or die "Can't git reset";
# do the commits
my @files = `git status --porcelain`;
foreach my $filename (@files) {
$filename =~ s/\A[AM ][AM ] // or die "Don't understand: $filename";
chomp $filename;
# create a commit message for this
my ($fh, $tempfilename) = tempfile();
print $fh "$filename: $log";
close $fh;
# commit it
system("git","add",$filename) == 0 or die "can't git add";
system("git","commit","-F",$tempfilename);
unlink $tempfilename;
}
exec("git rebase --continue");
PICKY:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;
tie my @array, 'Tie::File', shift or die "Can't tie filename";
foreach (@array) {
s/pick/edit/ && last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment