Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Make our git usage more efficient - Closes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
techman83 committed Apr 14, 2016
1 parent 39e34a7 commit 8b49996
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
21 changes: 12 additions & 9 deletions lib/App/KSP_CKAN/Tools/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Will perform a shallow clone of the repository

has 'remote' => ( is => 'ro', required => 1 );
has 'local' => ( is => 'ro', required => 1 );
has '_localgit' => ( is => 'ro', lazy => 1, builder => 1 ); # Internal Shortcut for our full Git Path
has 'working' => ( is => 'ro', lazy => 1, builder => 1 );
has 'clean' => ( is => 'ro', default => sub { 0 } );
has 'shallow' => ( is => 'ro', default => sub { 1 } );
Expand All @@ -76,14 +77,14 @@ method _build__git {
mkpath($self->local);
}

if ($self->clean) {
$self->_clean;
}

if ( ! -d $self->local."/".$self->working ) {
$self->_clone;
}

if ($self->clean) {
$self->_clean;
}

return Git::Wrapper->new({
dir => $self->local."/".$self->working,
});
Expand All @@ -108,11 +109,13 @@ method _clone {
}

method _clean {
local $CWD = $self->local;
if ( -d $self->working) {
remove_tree($self->working);
}
return;
# TODO: We could fail here too, we should return as such.
# NOTE: We've not instantiated a git object at this point, so
# we can't use it.
local $CWD = $self->local."/".$self->working;
capture { system("git", "reset", "--hard", "HEAD") };
capture { system("git", "clean", "-df") };

}

method _build_branch {
Expand Down
10 changes: 5 additions & 5 deletions t/App/KSP_CKAN/Tools/Git.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ my $git = App::KSP_CKAN::Tools::Git->new(
);
isa_ok($git, "App::KSP_CKAN::Tools::Git");

# Test Cleanup
mkpath($test->tmp."/CKAN-meta");
$git->_clean;
isnt($test->tmp."/CKAN-meta", 1, "Clean was successful");

# Test our clone
# Git gives benign 'warning: --depth is ignored in local clones; use file:// instead.'
# Local pulls don't honor depth, but we're only testing that we can clone.
Expand Down Expand Up @@ -109,6 +104,11 @@ unlink($test->tmp."/CKAN-meta/test_file.ckan");
$git->add;
is($git->changed, 2, "File delete not commited");

# Test cleanup
$test->create_ckan( $test->tmp."/CKAN-meta/cleaned_file.ckan" );
$git->_clean;
isnt(-e $test->tmp."/CKAN-meta/cleaned_file.ckan", 1, "Cleanup Successful");

subtest 'Git Errors' => sub {
my $remote_error = App::KSP_CKAN::Tools::Git->new(
remote => $test->tmp."/data/CKAN-meta",
Expand Down

0 comments on commit 8b49996

Please sign in to comment.