class BRocket::Git

Public Instance Methods

add_and_commit(filepath, msg) click to toggle source

This method is called from BRocket::VersionFile#bump_on

# File lib/brocket/git.rb, line 31
def add_and_commit(filepath, msg)
  sh("git add #{filepath} && git commit -m \"#{msg}\"")
end
already_tagged?() click to toggle source
# File lib/brocket/git.rb, line 69
def already_tagged?
  if sh_stdout('git tag').split(/\n/).include?(version_tag)
    $stderr.puts "Tag #{version_tag} has already been created."
    true
  end
end
clean?() click to toggle source
# File lib/brocket/git.rb, line 35
def clean?
  sh("git diff --exit-code")
  return true
rescue LoggerPipe::Failure
  return false
end
committed?() click to toggle source
# File lib/brocket/git.rb, line 42
def committed?
  sh("git diff-index --quiet --cached HEAD")
  return true
rescue LoggerPipe::Failure
  return false
end
get_sha(obj) click to toggle source
# File lib/brocket/git.rb, line 86
def get_sha(obj)
  sh_stdout("git show #{obj} --format=\"%H\" --quiet").strip
end
git_push() click to toggle source
# File lib/brocket/git.rb, line 59
def git_push
  perform_git_push
  perform_git_push '--tags'
  $stdout.puts "Pushed git commits and tags."
end
guard_clean() click to toggle source
# File lib/brocket/git.rb, line 9
def guard_clean
  if (clean? && committed?)
    if already_tagged? && !same_commit_as?(version_tag)
      error("#{version_tag} is already tagged to another commit")
    else
      success("[git guard_clean] OK")
    end
  else
    error("There are files that need to be committed first. Run `git status`")
  end
end
perform_git_push(options = nil) click to toggle source
# File lib/brocket/git.rb, line 65
def perform_git_push(options = nil)
  sh(['git push', options].compact.join(' ' ))
end
push() click to toggle source
# File lib/brocket/git.rb, line 22
def push
  info("[git push] starting")
  tag_version { git_push } unless already_tagged?
  success("[git push] OK")
end
same_commit_as?(tag) click to toggle source
# File lib/brocket/git.rb, line 82
def same_commit_as?(tag)
  get_sha(tag) == get_sha("HEAD")
end
tag_version() { || ... } click to toggle source
# File lib/brocket/git.rb, line 49
def tag_version
  sh "git tag -a -m \"Version #{version_tag}\" #{version_tag}"
  $stdout.puts "Tagged #{version_tag}."
  yield if block_given?
rescue
  $stderr.puts "Untagging #{version_tag} due to error."
  sh "git tag -d #{version_tag}"
  raise
end
version_tag() click to toggle source
# File lib/brocket/git.rb, line 76
def version_tag
  prefix = sub(Docker).config_hash["GIT_TAG_PREFIX"] || ""
  version = sub(VersionFile).current
  "%s%s" % [prefix, version]
end