Skip to content

Commit

Permalink
Allow git_repository to be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 30, 2023
1 parent 3f01ab4 commit 6bb8a46
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def sync_and_notify
end

def git_repository
(super || (ensure_git_repository && super)).tap { |r| sync_git_repository(r) }
(super || (ensure_git_repository && super))&.tap { |r| sync_git_repository(r) }
end

def verify_ssl=(val)
Expand Down Expand Up @@ -84,13 +84,17 @@ def sync
end

def checkout_git_repository(target_directory)
return if git_repository.nil?

git_repository.update_repo
git_repository.checkout(scm_branch, target_directory)
end

private

def ensure_git_repository
return if scm_url.blank?

transaction do
repo = GitRepository.create!(attrs_for_sync_git_repository)
if new_record?
Expand All @@ -106,6 +110,8 @@ def sync_git_repository(git_repository = nil)
return unless name_changed? || scm_url_changed? || authentication_id_changed? || @verify_ssl_changed

git_repository ||= self.git_repository
return if git_repository.nil?

git_repository.attributes = attrs_for_sync_git_repository
end

Expand Down

0 comments on commit 6bb8a46

Please sign in to comment.