Sha256: cee382f934b34c02e7a3e660269c223c48d07a8f876eb37a5dd235d8746b46c3

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

class KuberKit::Shell::Commands::GitCommands
  def get_remote_url(shell, git_repo_path, remote_name: "origin")
    shell.exec!([
      "cd #{git_repo_path}",
      "git config --get remote.#{remote_name}.url",
    ].join(" && "), merge_stderr: true)
  rescue KuberKit::Shell::AbstractShell::ShellError
    return nil
  end

  def get_branch_name(shell, git_repo_path, remote_name: "origin")
    shell.exec!([
      "cd #{git_repo_path}",
      "git rev-parse --abbrev-ref HEAD",
    ].join(" && "), merge_stderr: true)
  rescue KuberKit::Shell::AbstractShell::ShellError
    return nil
  end

  def get_version_hash(shell, git_repo_path)
    shell.exec!([
      "cd #{git_repo_path}",
      "git rev-parse --short HEAD",
    ].join(" && "), merge_stderr: true)
  end

  def download_repo(shell, remote_url:, path:, branch:)
    shell.exec!([
      "rm -rf #{path}",
      "mkdir -p #{path}",
      "git clone -b #{branch} --depth 1 #{remote_url} #{path}",
    ].join(" && "), merge_stderr: true)
  end

  def force_pull_repo(shell, path:, branch:)
    shell.exec!([
      "cd #{path}",
      "git add .",
      "git reset HEAD --hard",
      "git fetch origin #{branch}",
      "git checkout #{branch}",
      "git reset --hard '@{u}'",
      "git pull --force",
    ].join(" && "), merge_stderr: true)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kuber_kit-1.3.4 lib/kuber_kit/shell/commands/git_commands.rb
kuber_kit-1.1.6 lib/kuber_kit/shell/commands/git_commands.rb
kuber_kit-1.3.3 lib/kuber_kit/shell/commands/git_commands.rb