class Git::Branch
Attributes
full[RW]
name[RW]
remote[RW]
Public Class Methods
new(base, name)
click to toggle source
# File lib/git/branch.rb, line 9 def initialize(base, name) @full = name @base = base @gcommit = nil @stashes = nil @remote, @name = parse_name(name) end
Public Instance Methods
archive(file, opts = {})
click to toggle source
# File lib/git/branch.rb, line 31 def archive(file, opts = {}) @base.lib.archive(@full, file, opts) end
checkout()
click to toggle source
# File lib/git/branch.rb, line 26 def checkout check_if_create @base.checkout(@full) end
contains?(commit)
click to toggle source
# File lib/git/branch.rb, line 63 def contains?(commit) !@base.lib.branch_contains(commit, self.name).empty? end
create()
click to toggle source
# File lib/git/branch.rb, line 51 def create check_if_create end
current()
click to toggle source
# File lib/git/branch.rb, line 59 def current determine_current end
delete()
click to toggle source
# File lib/git/branch.rb, line 55 def delete @base.lib.branch_delete(@name) end
gcommit()
click to toggle source
# File lib/git/branch.rb, line 17 def gcommit @gcommit ||= @base.gcommit(@full) @gcommit end
in_branch(message = 'in branch work') { || ... }
click to toggle source
g.branch(‘new_branch’).in_branch do
# create new file # do other stuff return true # auto commits and switches back
end
# File lib/git/branch.rb, line 40 def in_branch(message = 'in branch work') old_current = @base.lib.branch_current checkout if yield @base.commit_all(message) else @base.reset_hard end @base.checkout(old_current) end
merge(branch = nil, message = nil)
click to toggle source
# File lib/git/branch.rb, line 67 def merge(branch = nil, message = nil) if branch in_branch do @base.merge(branch, message) false end # merge a branch into this one else # merge this branch into the current one @base.merge(@name) end end
stashes()
click to toggle source
# File lib/git/branch.rb, line 22 def stashes @stashes ||= Git::Stashes.new(@base) end
to_a()
click to toggle source
# File lib/git/branch.rb, line 84 def to_a [@full] end
to_s()
click to toggle source
# File lib/git/branch.rb, line 88 def to_s @full end
update_ref(commit)
click to toggle source
# File lib/git/branch.rb, line 80 def update_ref(commit) @base.lib.update_ref(@full, commit) end
Private Instance Methods
check_if_create()
click to toggle source
# File lib/git/branch.rb, line 94 def check_if_create @base.lib.branch_new(@name) rescue nil end
determine_current()
click to toggle source
# File lib/git/branch.rb, line 98 def determine_current @base.lib.branch_current == @name end
parse_name(name)
click to toggle source
Given a full branch name return an Array containing the remote and branch names.
Removes ‘remotes’ from the beggining of the name (if present). Takes the second part (splittign by ‘/’) as the remote name. Takes the rest as the repo name (can also hold one or more ‘/’).
Example:
parse_name('master') #=> [nil, 'master'] parse_name('origin/master') #=> ['origin', 'master'] parse_name('remotes/origin/master') #=> ['origin', 'master'] parse_name('origin/master/v2') #=> ['origin', 'master/v2']
param [String] name branch full name. return [<Git::Remote,NilClass,String>] an Array containing the remote and branch names.
# File lib/git/branch.rb, line 116 def parse_name(name) if name.match(/^(?:remotes)?\/([^\/]+)\/(.+)/) return [Git::Remote.new(@base, $1), $2] end return [nil, name] end