Sha256: 1a59786dee0ffd551adf5d3d7cad4f755109b5ff11154cd690709f2b4823c3cc

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

class KuberKit::ArtifactsSync::Strategies::GitUpdater < KuberKit::ArtifactsSync::Strategies::Abstract

  include KuberKit::Import[
    "shell.git_commands",
    "shell.bash_commands",
  ]

  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
  def update(shell, artifact)
    already_cloned = artifact_already_cloned?(
      shell:      shell,
      repo_path:  artifact.cloned_path,
      artifact:   artifact
    )

    if already_cloned
      git_commands.force_pull_repo(shell, 
        path: artifact.cloned_path, branch: artifact.branch
      )
    else
      git_commands.download_repo(shell, 
        remote_url: artifact.remote_url, path: artifact.cloned_path, branch: artifact.branch
      )
    end
  end

  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
  def cleanup(shell, artifact)
    bash_commands.rm_rf(shell, artifact.cloned_path)
  end

  private
    def artifact_already_cloned?(shell:, repo_path:, artifact:)
      target_remote_url = git_commands.get_remote_url(shell, repo_path)
      if target_remote_url != artifact.remote_url
        return false
      end

      target_branch = git_commands.get_branch_name(shell, repo_path)
      if target_branch != artifact.branch
        return false
      end

      return true
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kuber_kit-1.1.6 lib/kuber_kit/artifacts_sync/strategies/git_updater.rb
kuber_kit-1.3.3 lib/kuber_kit/artifacts_sync/strategies/git_updater.rb