Skip to content

Commit

Permalink
Add a block option to checkout_git_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 16, 2024
1 parent c4e8ef0 commit 3f979d4
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,22 @@ def sync
raise NotImplementedError, N_("sync must be implemented in a subclass")
end

def checkout_git_repository(target_directory)
def checkout_git_repository(target_directory = nil)
return if git_repository.nil?

target_directory_given = !!target_directory
target_directory ||= Pathname.new(Dir.mktmpdir)

git_repository.update_repo
git_repository.checkout(scm_branch, target_directory)

return target_directory unless block_given?

begin
yield target_directory
ensure
FileUtils.rm_rf(target_directory) unless target_directory_given
end
end

private
Expand Down

0 comments on commit 3f979d4

Please sign in to comment.