App-BatchRelease
view release on metacpan or search on metacpan
lib/App/BatchRelease/Source/Git.pm view on Meta::CPAN
sub pull ($self) {
local $ENV{GIT_TERMINAL_PROMPT} = 0;
$self->git(qw{pull --quiet --no-rebase --ff-only});
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::BatchRelease::Source::Git - A local git checkout, as App::BatchRelease::State reads it
=head1 VERSION
version 0.001
=head1 SYNOPSIS
use 5.040;
use App::BatchRelease::Source::Git;
my $source = App::BatchRelease::Source::Git->new( root => '/bogus/Foo-Bar' );
my $branch = $source->default_branch;
my $ahead = $source->compare( '0.002', $branch );
=head1 DESCRIPTION
The source of L<App::BatchRelease::State/THE SOURCE> for a checkout on this
machine. It runs the git program in the checkout, which must be git 2.23
or later, for C<git switch>.
Three methods write, and the rest only read: they change no file, ref or
configuration. C<git status> runs with C<--no-optional-locks>, so it does
not even refresh the index. The three that write are these:
=over
=item *
L</fetch> changes the refs of a remote and the tags, and no local branch or
work tree.
=item *
L</switch> and L</pull> change the branch that is checked out and the work
tree. L<App::BatchRelease> calls them only with C<--pull-latest>, and never
on a dry run.
=back
None of them stashes, merges, rebases or resets. The two that talk to a
remote run with C<GIT_TERMINAL_PROMPT=0>, so that git fails, rather than asks
for a password at the terminal.
Every command runs through L</git>, with a timeout, so a test can replace that
one method.
=head1 ATTRIBUTES
=head2 root
The directory of the checkout. Required.
=head2 id
The name that the result of L<App::BatchRelease::State/release_state>
carries as C<repo>. Default L</root>.
=head2 timeout
Seconds for each git command. Default 60.
=head2 tips
A hash reference from the name of a branch to the ref that L</file> and
L</compare> read for that branch, in place of C<refs/heads/$branch>. Default
empty. A dry run with C<--pull-latest> points the default branch at its
upstream, so that the state is the one that the fast-forward would give.
=head1 METHODS
=head2 git
C<(@args)>. Runs git with C<@args> in L</root>. Standard input is empty.
Returns a string, the standard output. In list context, it returns the exit
status and the standard output.
my $head = $source->git(qw{rev-parse HEAD});
my ( $status, $out ) = $source->git(qw{symbolic-ref --quiet HEAD});
In scalar context, it dies with the standard error when git exits with a
status other than 0.
=head2 is_checkout
Returns an integer: 1 when L</root> is the top of the work tree of a git
repository, and 0 for a directory inside one or no repository at all.
die "not a checkout\n" if !$source->is_checkout;
=head2 tip
C<($branch)>.
Returns a string, the ref that stands for the branch C<$branch>: the one that
L</tips> gives, else C<refs/heads/$branch>.
my $ref = $source->tip('main'); # refs/heads/main
=head2 file
C<($path)>.
( run in 0.721 second using v1.01-cache-2.11-cpan-f5f21f1076c )