class Githole::Git

Public Class Methods

new(version) click to toggle source
# File lib/githole/git.rb, line 4
def initialize(version)
  @version = version
end

Public Instance Methods

add() click to toggle source
# File lib/githole/git.rb, line 12
def add
  checkout master
  fetch
  if branch_exists?("remotes/origin/#{remote}")
    git "checkout -b #{remote} origin/#{remote}"
    pull remote
  else
    create remote
    git_push remote
    git "branch -u origin/#{remote}"
  end
  create local
end
count() click to toggle source
# File lib/githole/git.rb, line 72
def count
  git "rev-list HEAD --count"
end
push() click to toggle source
# File lib/githole/git.rb, line 42
def push
  update
  checkout remote
  merge local
  git_push remote
  checkout local
end
release() click to toggle source
# File lib/githole/git.rb, line 63
def release
  tag
  create "release"
  pull "release"
  merge master
  git_push "release"
  checkout master
end
remove() click to toggle source
# File lib/githole/git.rb, line 50
def remove
  checkout master
  delete remote
  delete local
end
respond_to?(cmd) click to toggle source
# File lib/githole/git.rb, line 8
def respond_to?(cmd)
  ['add','update','push','remove','tag','release','count'].include?(cmd)
end
tag() click to toggle source
# File lib/githole/git.rb, line 56
def tag
  checkout master
  pull master
  git "tag -a #{@version} -m #{@version}"
  git_push "--tags"
end
update() click to toggle source
# File lib/githole/git.rb, line 26
def update
  verify remote
  verify local
  # update master
  checkout master
  pull master
  # update remote
  checkout remote
  pull remote
  # merge master into remote
  merge master
  # rebase remote onto local
  checkout local
  rebase remote
end

Private Instance Methods

branch_exists?(branch) click to toggle source
# File lib/githole/git.rb, line 133
def branch_exists?(branch)
  branches.include?(branch)
end
branches() click to toggle source
# File lib/githole/git.rb, line 86
def branches
  `git branch -a`
    .split("\n")
    .collect { |b| b.split(' ').last }
    .collect { |b| b.split(' ').first }
end
checkout(branch, options = '') click to toggle source
# File lib/githole/git.rb, line 93
def checkout(branch, options = '')
  git "checkout #{options} #{branch}"
end
create(branch) click to toggle source
# File lib/githole/git.rb, line 97
def create(branch)
  branch_exists?(branch) ? checkout(branch) : checkout(branch, '-b')
end
delete(branch) click to toggle source
# File lib/githole/git.rb, line 101
def delete(branch)
  git "branch -D #{branch}"
end
fetch() click to toggle source
# File lib/githole/git.rb, line 82
def fetch
  git "fetch"
end
git(cmd) click to toggle source
# File lib/githole/git.rb, line 78
def git(cmd)
  system("git #{cmd}")
end
git_push(branch) click to toggle source
# File lib/githole/git.rb, line 105
def git_push(branch)
  git "push origin #{branch}"
end
local() click to toggle source
# File lib/githole/git.rb, line 129
def local
  "local-#{@version}"
end
local_exists?() click to toggle source
# File lib/githole/git.rb, line 141
def local_exists?
  branch_exists?(local)
end
master() click to toggle source
# File lib/githole/git.rb, line 121
def master
  "master"
end
merge(branch) click to toggle source
# File lib/githole/git.rb, line 117
def merge(branch)
  git "merge #{branch}"
end
pull(branch) click to toggle source
# File lib/githole/git.rb, line 109
def pull(branch)
  git "pull origin #{branch}"
end
rebase(branch) click to toggle source
# File lib/githole/git.rb, line 113
def rebase(branch)
  git "rebase #{branch}"
end
remote() click to toggle source
# File lib/githole/git.rb, line 125
def remote
  "#{@version}"
end
remote_exists?() click to toggle source
# File lib/githole/git.rb, line 137
def remote_exists?
  branch_exists?(remote)
end
verify(branch) click to toggle source
# File lib/githole/git.rb, line 145
def verify(branch)
  create(branch) unless branch_exists?(branch)
end