Class: KuberKit::Shell::Commands::GitCommands

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/shell/commands/git_commands.rb

Instance Method Summary collapse

Instance Method Details

#download_repo(shell, remote_url:, path:, branch:) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/kuber_kit/shell/commands/git_commands.rb', line 27

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

#force_pull_repo(shell, path:, branch:) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/kuber_kit/shell/commands/git_commands.rb', line 35

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

#get_branch_name(shell, git_repo_path, remote_name: "origin") ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/kuber_kit/shell/commands/git_commands.rb', line 11

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

#get_remote_url(shell, git_repo_path, remote_name: "origin") ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/kuber_kit/shell/commands/git_commands.rb', line 2

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

#get_version_hash(shell, git_repo_path) ⇒ Object



20
21
22
23
24
25
# File 'lib/kuber_kit/shell/commands/git_commands.rb', line 20

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