class SRC::Git::Branch

Constants

AHEAD
BEHIND
DIVERGED
VERSION_FILE

Attributes

name[R]

Public Class Methods

checked_out() click to toggle source
# File lib/src/git/branch.rb, line 12
def checked_out
  new(`git rev-parse --abbrev-ref HEAD`.chomp)
end
latest(prefix) click to toggle source
# File lib/src/git/branch.rb, line 16
def latest(prefix)
  branch_name = `git branch`.split(/\s+/).select { |b| b =~ /\A#{prefix}/ }.max
  new(branch_name) if branch_name
end
new(name) click to toggle source
# File lib/src/git/branch.rb, line 22
def initialize(name)
  @name = name.to_s
end

Public Instance Methods

==(other) click to toggle source
# File lib/src/git/branch.rb, line 124
def ==(other)
  name == other.to_s
end
add(filename) click to toggle source
# File lib/src/git/branch.rb, line 65
def add(filename)
  checked_out do
    raise unless system("git add #{filename}")
  end
end
branch_from(new_branch) click to toggle source
# File lib/src/git/branch.rb, line 71
def branch_from(new_branch)
  checked_out do
    raise unless system("git branch #{new_branch}")
  end
  self.class.new(new_branch)
end
checked_out() { || ... } click to toggle source
# File lib/src/git/branch.rb, line 78
def checked_out
  previous_branch = self.class.checked_out
  self.checkout
  yield
ensure
  previous_branch.checkout
end
checked_out?() click to toggle source
# File lib/src/git/branch.rb, line 35
def checked_out?
  self.class.checked_out == self
end
checkout() click to toggle source
# File lib/src/git/branch.rb, line 30
def checkout
  msg = `git checkout #{name} -q`
  raise msg unless $?.success?
end
commit(msg) click to toggle source
# File lib/src/git/branch.rb, line 59
def commit(msg)
  checked_out do
    raise unless system("git commit -m '#{msg}' -q")
  end
end
exists?() click to toggle source
# File lib/src/git/branch.rb, line 26
def exists?
  system("git show-ref --verify --quiet refs/heads/'#{name}'")
end
merge(other_branch) click to toggle source
# File lib/src/git/branch.rb, line 86
def merge(other_branch)
  checked_out do
    raise unless system("git merge --no-ff #{other_branch}")
  end
end
remote_ahead?() click to toggle source
# File lib/src/git/branch.rb, line 104
def remote_ahead?
  status =~ AHEAD
end
remote_behind?() click to toggle source
# File lib/src/git/branch.rb, line 108
def remote_behind?
  status =~ BEHIND
end
remote_diverged?() click to toggle source
# File lib/src/git/branch.rb, line 112
def remote_diverged?
  status =~ DIVERGED
end
remote_up_to_date?() click to toggle source
# File lib/src/git/branch.rb, line 116
def remote_up_to_date?
  !(remote_diverged? || remote_behind? || remote_ahead?)
end
status() click to toggle source
# File lib/src/git/branch.rb, line 98
def status
  checked_out do
    `git status -uno`.chomp
  end
end
subset_of?(other_branch) click to toggle source
# File lib/src/git/branch.rb, line 39
def subset_of?(other_branch)
  `git rev-list #{other_branch}..#{name}`.chomp.length == 0
end
tag() click to toggle source
# File lib/src/git/branch.rb, line 92
def tag
  checked_out do
    raise unless system("git tag #{version}")
  end
end
to_s() click to toggle source
# File lib/src/git/branch.rb, line 120
def to_s
  name
end
update_version_file(new_version) click to toggle source
# File lib/src/git/branch.rb, line 51
def update_version_file(new_version)
  checked_out do
    raise unless system("echo '#{new_version}' > #{version_file}")
    self.add(version_file)
    self.commit("version bumped to #{new_version}")
  end
end
version() click to toggle source
# File lib/src/git/branch.rb, line 43
def version
  `git show #{name}:#{version_file}`.chomp
end
version_file() click to toggle source
# File lib/src/git/branch.rb, line 47
def version_file
  VERSION_FILE
end