our
$AUTHORITY
=
'cpan:GENEHACK'
;
$App::GitGot::Repo::Git::VERSION
=
'1.339'
;
use
5.014;
has
'+type'
=> (
default
=>
'git'
);
has
'_wrapper'
=> (
is
=>
'lazy'
,
isa
=> GitWrapper ,
handles
=> [
qw/
checkout
cherry
clone
config
fetch
gc
pull
push
remote
status
symbolic_ref
/
] ,
);
sub
_build__wrapper {
my
$self
=
shift
;
if
(
$ENV
{GITGOT_FAKE_GIT_WRAPPER} ) {
my
$mock
= Test::MockObject->new;
$mock
->set_isa(
'Git::Wrapper'
);
foreach
my
$method
(
qw/ cherry clone fetch gc pull
remote symbolic_ref /
) {
$mock
->mock(
$method
=>
sub
{
return
(
'1'
)});
}
$mock
->mock(
'checkout'
=>
sub
{ } );
$mock
->mock(
'status'
=>
sub
{
package
MyFake;
sub
get {
return
() };
return
bless
{} ,
'MyFake'
} );
$mock
->mock(
'config'
=>
sub
{ 0 });
$mock
->mock(
'ERR'
=>
sub
{ [ ] });
return
$mock
}
else
{
return
Git::Wrapper->new(
$self
->path )
||
die
"Can't make Git::Wrapper"
;
}
}
sub
current_branch {
my
$self
=
shift
;
my
$branch
;
try
{
(
$branch
) =
$self
->symbolic_ref(
'HEAD'
);
$branch
=~ s|^refs/heads/||
if
$branch
;
}
catch
{
die
$_
unless
$_
&&
$_
->isa(
'Git::Wrapper::Exception'
)
&&
$_
->error eq
"fatal: ref HEAD is not a symbolic ref\n"
};
return
$branch
;
}
sub
current_remote_branch {
my
(
$self
) =
shift
;
my
$remote
= 0;
if
(
my
$branch
=
$self
->current_branch ) {
try
{
(
$remote
) =
$self
->config(
"branch.$branch.remote"
);
}
catch
{
return
0
if
$_
&&
$_
->isa(
'Git::Wrapper::Exception'
) &&
$_
->{status} eq
'1'
;
};
}
return
$remote
;
}
1;