class Serverkit::Resources::Git

Constants

DEFAULT_STATE

Public Instance Methods

apply() click to toggle source

@note Override

# File lib/serverkit/resources/git.rb, line 14
def apply
  _clone if clonable?
  checkout if checkoutable?
  update if updatable?
end
check() click to toggle source

@note Override

# File lib/serverkit/resources/git.rb, line 21
def check
  has_git? && cloned? && !checkoutable? && !updatable?
end

Private Instance Methods

_clone() click to toggle source

@note clone is reserved ;(

# File lib/serverkit/resources/git.rb, line 32
def _clone
  run_command("git clone #{repository} #{path}")
end
checkout() click to toggle source
# File lib/serverkit/resources/git.rb, line 44
def checkout
  run_command("git -C #{path} checkout #{branch}")
end
checkoutable?() click to toggle source
# File lib/serverkit/resources/git.rb, line 40
def checkoutable?
  branch && !checkouted?
end
checkouted?() click to toggle source
# File lib/serverkit/resources/git.rb, line 48
def checkouted?
  check_command("cd #{path} && test `git rev-parse HEAD` = `git rev-parse #{branch}`")
end
clonable?() click to toggle source
# File lib/serverkit/resources/git.rb, line 27
def clonable?
  !cloned?
end
cloned?() click to toggle source
# File lib/serverkit/resources/git.rb, line 36
def cloned?
  check_command_from_identifier(:check_file_is_directory, git_path)
end
git_path() click to toggle source

@return [String] Path to .git directory in the cloned repository

# File lib/serverkit/resources/git.rb, line 53
def git_path
  ::File.join(path, ".git")
end
has_git?() click to toggle source
# File lib/serverkit/resources/git.rb, line 57
def has_git?
  check_command("which git")
end
local_head_revision() click to toggle source

@return [String]

# File lib/serverkit/resources/git.rb, line 62
def local_head_revision
  run_command("cd #{path} && git rev-parse HEAD").stdout.rstrip
end
origin_head_revision() click to toggle source

@return [String]

# File lib/serverkit/resources/git.rb, line 67
def origin_head_revision
  run_command("cd #{path} && git ls-remote origin HEAD").stdout.split.first
end
updatable?() click to toggle source
# File lib/serverkit/resources/git.rb, line 71
def updatable?
  state == "updated" && !updated?
end
update() click to toggle source
# File lib/serverkit/resources/git.rb, line 75
def update
  run_command("cd #{path} && git fetch origin && git reset --hard FETCH_HEAD")
end
updated?() click to toggle source
# File lib/serverkit/resources/git.rb, line 79
def updated?
  local_head_revision == origin_head_revision
end