Class: Branchtree::Branch
- Inherits:
-
Object
- Object
- Branchtree::Branch
- Includes:
- Context
- Defined in:
- lib/branchtree/branch.rb
Overview
Represents a git branch in the current repository.
Defined Under Namespace
Classes: Info, InvalidInfo, NullInfo
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#info ⇒ Object
Returns the value of attribute info.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.load(node, parent) ⇒ Object
Recursively load a Branch instance and its children, if any, from deserialized YAML.
Instance Method Summary collapse
-
#checkout ⇒ Object
Checkout this branch with git.
-
#full_ref ⇒ Object
Return the full git ref name of this branch.
-
#initialize(name, parent, rebase) ⇒ Branch
constructor
A new instance of Branch.
- #merge_parent ⇒ Object
-
#parent_branch_name ⇒ Object
Return the String name of the ref that this branch is based on.
- #rebase? ⇒ Boolean
- #rebase_parent ⇒ Object
- #root? ⇒ Boolean
Methods included from Context
Constructor Details
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
18 19 20 |
# File 'lib/branchtree/branch.rb', line 18 def children @children end |
#info ⇒ Object
Returns the value of attribute info.
19 20 21 |
# File 'lib/branchtree/branch.rb', line 19 def info @info end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/branchtree/branch.rb', line 18 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
18 19 20 |
# File 'lib/branchtree/branch.rb', line 18 def parent @parent end |
Class Method Details
.load(node, parent) ⇒ Object
Recursively load a Branch instance and its children, if any, from deserialized YAML.
9 10 11 12 13 14 15 16 |
# 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 |
Instance Method Details
#checkout ⇒ Object
Checkout this branch with git
55 56 57 |
# File 'lib/branchtree/branch.rb', line 55 def checkout qcmd.run("git", "checkout", name) end |
#full_ref ⇒ Object
Return the full git ref name of this branch.
50 51 52 |
# File 'lib/branchtree/branch.rb', line 50 def full_ref "refs/heads/#{name}" end |
#merge_parent ⇒ Object
59 60 61 |
# File 'lib/branchtree/branch.rb', line 59 def merge_parent qcmd.run!("git", "merge", parent_branch_name) end |
#parent_branch_name ⇒ Object
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”.
39 40 41 42 43 44 45 46 47 |
# 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? ⇒ Boolean
33 34 35 |
# File 'lib/branchtree/branch.rb', line 33 def rebase? @rebase end |
#rebase_parent ⇒ Object
63 64 65 |
# File 'lib/branchtree/branch.rb', line 63 def rebase_parent qcmd.run!("git", "rebase", parent_branch_name) end |
#root? ⇒ Boolean
29 30 31 |
# File 'lib/branchtree/branch.rb', line 29 def root? @parent.nil? end |