App-Git-Autofixup
view release on metacpan or search on metacpan
available.
# 0.004000
- Automatically choose an upstream revision if one isn't supplied, based on the
upstream/tracking branch. Thanks to Walter Smuts and Johannes Altmanninger
for their help in figuring out the details.
- Support quoted filenames in diff output. git-autofixup now works with
filenames containing non-ASCII characters.
- Improve error messages and handling. For git commands that are expected to
fail, their stderr is captured, annotated with the command, and printed, to
clarify the cause of errors.
- Deprecate --gitopt|-g in favor of using the GIT_CONFIG_{COUNT,KEY,VALUE}
environment variables.
# 0.003002
- Speed up creation of temporary git index by copying the existing one and
subtracting recent changes
- Speed up `git-blame` by only considering commits since the given revision
- Handle filenames (in git diff output) that contain spaces
git-autofixup view on Meta::CPAN
# rebase meatadata.
my $gitdir = git_dir();
if (-e "$gitdir/rebase-merge") {
my $branch = slurp("$gitdir/rebase-merge/head-name");
chomp $branch;
$branch =~ s#^refs/heads/##;
$upstream = "$branch\@{upstream}";
}
# `git merge-base` will fail if there's no tracking branch. In that case
# redirect stderr and communicate failure by returning an empty list. Also,
# with the --fork-point option, no merge bases are returned if the relevant
# reflog entries have been GC'd, so fall back to normal merge-bases.
my @merge_bases = ();
my ($out, $err, $exit_code) = capture(qw(git merge-base --all --fork-point), $upstream, 'HEAD');
if ($exit_code == 0) {
@merge_bases = map {chomp; $_} split(/\n/, $out);
} else {
my ($out, $err, $exit_code) = capture(qw(git merge-base --all), $upstream, 'HEAD');
if ($exit_code != 0) {
die "git merge-base: $err";
git-autofixup view on Meta::CPAN
sub toplevel_dir {
my ($out, $err, $exit_code) = capture(qw(git rev-parse --show-toplevel));
if ($exit_code != 0) {
warn "git rev-parse --show-toplevel: $err\n";
die "Can't find repo's toplevel dir\n";
}
chomp $out;
return $out;
}
# Run the given command, capture stdout and stderr, and return an array of
# (stdout, stderr, exit_code).
sub capture {
open(my $out_fh, '>', undef) or die "create stdout tempfile: $!";
open(my $err_fh, '>', undef) or die "create stderr tempfile: $!";
my $pid = open3(my $in_fh, $out_fh, $err_fh, @_);
waitpid $pid, 0;
if ($? & 127) {
my $signal = $? & 127;
die "capture: child died with signal $signal; exiting";
}
my $exit_code = $? >> 8;
local $/; # slurp
my $stdout = readline $out_fh;
my $stderr = readline $err_fh;
my @array = ($stdout, $stderr, $exit_code);
return wantarray ? @array : \@array;
}
# Return a description of what $? means.
sub child_error_desc {
my $err = shift;
if ($err == -1) {
return "failed to execute: $!";
} elsif ($err & 127) {
return "died with signal " . ($err & 127);
t/capture.t view on Meta::CPAN
plan tests => 3;
sub test_capture {
my %args = @_;
my @cmd = ref $args{cmd} ? @{$args{cmd}} : ($args{cmd});
my $got = Autofixup::capture(@cmd);
is_deeply($got, $args{want}, $args{name});
}
test_capture(
name => 'capture stdout, stderr, and exit_code',
cmd => q(perl -e 'print STDERR "stderr\n"; print "stdout\n"; exit 3'),
want => ["stdout\n", "stderr\n", 3],
);
test_capture(
name => 'capture echo command given as list',
cmd => [qw(echo stdout)],
want => ["stdout\n", '', 0],
);
test_capture(
name => 'capture echo with redirection',
cmd => "echo stderr 1>&2",
want => ['', "stderr\n", 0],
);
( run in 1.035 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )