From c2e2e8d04e50592f7dfc419fc07fe9ec63a45fbd Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Mon, 29 Jul 2024 21:30:42 -0700 Subject: [PATCH 1/3] Invert the logic here... [#75] ...and let Git do most of the work instead of trying to out-think it. --- lib/App/GitGot/Command.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/App/GitGot/Command.pm b/lib/App/GitGot/Command.pm index 7d10633..4f6579c 100644 --- a/lib/App/GitGot/Command.pm +++ b/lib/App/GitGot/Command.pm @@ -337,18 +337,20 @@ sub _git_clone_or_callback { my $path = $entry->path; - if ( !-d $path ) { - path($path)->mkpath; - - try { - $entry->clone( $entry->repo , './' ); - $msg .= $self->major_change('Checked out'); - } + if ( -d "$path/.git" ) { + # repo already exists and is checked out, just call the callback + try { + $msg .= $callback->( $msg , $entry ); + } catch { $msg .= $self->error('ERROR') . "\n$_" }; } - elsif ( -d "$path/.git" ) { + else { + # if the directory exists and is non-empty, git will blow up, but that's + # okay. if the directory doesn't exist, git will handle creating it; it + # will also DTRT if the directory is empty and exists try { - $msg .= $callback->($msg , $entry); + $entry->clone( $entry->repo , $path ); + $msg .= $self->major_change('Checked out'); } catch { $msg .= $self->error('ERROR') . "\n$_" }; } From 19c969e2965709d5fbe8d1ce91073655c364ed37 Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Mon, 29 Jul 2024 21:37:07 -0700 Subject: [PATCH 2/3] Misc whitespace [#75] --- lib/App/GitGot/Command.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/App/GitGot/Command.pm b/lib/App/GitGot/Command.pm index 4f6579c..111ad81 100644 --- a/lib/App/GitGot/Command.pm +++ b/lib/App/GitGot/Command.pm @@ -333,8 +333,7 @@ sub _git_clone_or_callback { my( $self , $entry , $callback ) = @_ or die "Need entry and callback"; - my $msg = ''; - + my $msg = ''; my $path = $entry->path; if ( -d "$path/.git" ) { @@ -356,7 +355,6 @@ sub _git_clone_or_callback { } return $msg; - } sub _git_fetch { From df17b909b931d99ea6b455c93324a382a13a4bda Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Mon, 29 Jul 2024 21:39:56 -0700 Subject: [PATCH 3/3] Update .gitignore [#75] --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 9fa7365..e2b2217 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ .build +blib extlib +pm_to_blib App-GitGot-* +Makefile +Makefile.old +MYMETA.* !releases/*.tar.gz