class Branchtree::Branch
Represents a git branch in the current repository.
Attributes
children[R]
info[RW]
name[R]
parent[R]
Public Class Methods
load(node, parent)
click to toggle source
Recursively load a Branch
instance and its children, if any, from deserialized YAML.
# File lib/branchtree/branch.rb, line 9 def self.load(node, parent) new(node.fetch("branch"), parent, node.fetch("rebase", false)).tap do |branch| node.fetch("children", []).each do |child_node| branch.children << load(child_node, branch) end branch.children.freeze end end
new(name, parent, rebase)
click to toggle source
# File lib/branchtree/branch.rb, line 21 def initialize(name, parent, rebase) @name = name @parent = parent @rebase = rebase @children = [] @info = NullInfo.new(self) end
Public Instance Methods
checkout()
click to toggle source
Checkout this branch with git
# File lib/branchtree/branch.rb, line 55 def checkout qcmd.run("git", "checkout", name) end
full_ref()
click to toggle source
Return the full git ref name of this branch.
# File lib/branchtree/branch.rb, line 50 def full_ref "refs/heads/#{name}" end
merge_parent()
click to toggle source
# File lib/branchtree/branch.rb, line 59 def merge_parent qcmd.run!("git", "merge", parent_branch_name) end
parent_branch_name()
click to toggle source
Return the String name of the ref that this branch is based on. New changes to this parent ref will be merged in on “apply”.
# File lib/branchtree/branch.rb, line 39 def parent_branch_name return @parent.name if @parent if cmd.run!("git", "rev-parse", "--verify", "--quiet", "refs/heads/main").success? "main" else "master" end end
rebase?()
click to toggle source
# File lib/branchtree/branch.rb, line 33 def rebase? @rebase end
rebase_parent()
click to toggle source
# File lib/branchtree/branch.rb, line 63 def rebase_parent qcmd.run!("git", "rebase", parent_branch_name) end
root?()
click to toggle source
# File lib/branchtree/branch.rb, line 29 def root? @parent.nil? end