class Prodder::Git

Constants

GitError
NotFastForward
NotFoundError

Public Class Methods

new(local, remote) click to toggle source
# File lib/prodder/git.rb, line 14
def initialize(local, remote)
  @local  = local
  @remote = remote
end

Public Instance Methods

add(file) click to toggle source
# File lib/prodder/git.rb, line 65
def add(file)
  inside_repo { git 'add', file }
end
checkout(branch) click to toggle source
# File lib/prodder/git.rb, line 57
def checkout(branch)
  inside_repo { git 'checkout', branch }
end
clone() click to toggle source
# File lib/prodder/git.rb, line 49
def clone
  git 'clone', @remote, @local
end
clone_or_remote_update() click to toggle source
# File lib/prodder/git.rb, line 19
def clone_or_remote_update
  if File.directory? File.join(@local, '.git')
    remote_update
    checkout 'master'
    reset    'origin/master', true
  else
    clone
  end
end
commit(message, author) click to toggle source
# File lib/prodder/git.rb, line 69
def commit(message, author)
  inside_repo { git 'commit', "--author='#{author}'", "-m", message }
end
dirty?() click to toggle source
# File lib/prodder/git.rb, line 29
def dirty?
  inside_repo { git('status', '--porcelain') != '' }
end
fast_forward?() click to toggle source
# File lib/prodder/git.rb, line 43
def fast_forward?
  inside_repo do
    git('merge-base', 'master', 'origin/master') == git('show-ref', '--hash', 'origin/master')
  end
end
no_new_commits?() click to toggle source
# File lib/prodder/git.rb, line 37
def no_new_commits?
  inside_repo do
    git('show-ref', '--hash', 'origin/master') == git('show-ref', '--hash', 'refs/heads/master')
  end
end
push() click to toggle source
# File lib/prodder/git.rb, line 73
def push
  inside_repo { git 'push', 'origin', 'master:master' }
end
remote_update() click to toggle source
# File lib/prodder/git.rb, line 53
def remote_update
  inside_repo { git 'remote', 'update' }
end
reset(sharef, hard = false) click to toggle source
# File lib/prodder/git.rb, line 61
def reset(sharef, hard = false)
  inside_repo { git 'reset', hard ? '--hard' : '', sharef }
end
tracked?(file) click to toggle source
# File lib/prodder/git.rb, line 33
def tracked?(file)
  inside_repo { git('ls-files', file) != '' }
end

Private Instance Methods

git(*cmd, &block) click to toggle source
# File lib/prodder/git.rb, line 83
def git(*cmd, &block)
  cmd = ['git', *cmd]

  Open3.popen3(*cmd) do |stdin, out, err, thr|
    out = out.read
    err = err.read
    raise GitError.new(cmd.join(' '), err) if !thr.value.success?
    block.call(out, err, thr) if block
    out
  end
rescue Errno::ENOENT
  raise NotFoundError
end
inside_repo(&block) click to toggle source
# File lib/prodder/git.rb, line 79
def inside_repo(&block)
  Dir.chdir @local, &block
end