Handle corrupt git clones
When cloning the git repo: 1. Try to clone 2. If there's already a build directory reset it 3. Check the clone is valid If anything goes wrong during that process: 1. Delete the clone directory 2. Clone it again 3. Check the clone is valid Raise any errors after that
This commit is contained in:
@@ -23,7 +23,9 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
||||
say "Building from a local git clone, so ignoring these uncommitted changes:\n #{uncommitted_changes}", :yellow
|
||||
end
|
||||
|
||||
prepare_clone
|
||||
run_locally do
|
||||
Clone.new(self).prepare
|
||||
end
|
||||
elsif uncommitted_changes.present?
|
||||
say "Building with uncommitted changes:\n #{uncommitted_changes}", :yellow
|
||||
end
|
||||
@@ -126,23 +128,4 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_clone
|
||||
run_locally do
|
||||
begin
|
||||
info "Cloning repo into build directory `#{KAMAL.config.builder.build_directory}`..."
|
||||
|
||||
execute *KAMAL.builder.create_clone_directory
|
||||
execute *KAMAL.builder.clone
|
||||
rescue SSHKit::Command::Failed => e
|
||||
if e.message =~ /already exists and is not an empty directory/
|
||||
info "Resetting local clone as `#{KAMAL.config.builder.build_directory}` already exists..."
|
||||
|
||||
KAMAL.builder.clone_reset_steps.each { |step| execute *step }
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user