Class: GitChain::Chain
- Inherits:
-
Struct
- Object
- Struct
- GitChain::Chain
- Defined in:
- lib/git_chain/chain.rb
Instance Attribute Summary collapse
-
#git ⇒ Object
Returns the value of attribute git.
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
- #mark_branch_as_dependent(child:, parent:, old_base: nil) ⇒ Object
- #rebase(child) ⇒ Object
- #rebase_all(child) ⇒ Object
Instance Attribute Details
#git ⇒ Object
Returns the value of attribute git
1 2 3 |
# File 'lib/git_chain/chain.rb', line 1 def git @git end |
#storage ⇒ Object
Returns the value of attribute storage
1 2 3 |
# File 'lib/git_chain/chain.rb', line 1 def storage @storage end |
Instance Method Details
#mark_branch_as_dependent(child:, parent:, old_base: nil) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/git_chain/chain.rb', line 3 def mark_branch_as_dependent(child:, parent:, old_base: nil) old_base = old_base || parent base = calculate_base(child, old_base: old_base) update_dependent(child: child, parent: parent, base: base) storage.save_data end |
#rebase(child) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_chain/chain.rb', line 10 def rebase(child) raise "No chain for #{child}" unless record = storage.record_for(child) raise "Git Directory is not clean" unless git.clean? old_base = record[:base] parent = record[:parent] branch = git.branches[parent] new_base = branch.gcommit git.rebase_onto(new_base: new_base, old_base: old_base, branch: child) update_dependent(child: child, parent: parent, base: new_base.sha) end |
#rebase_all(child) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git_chain/chain.rb', line 24 def rebase_all(child) raise "Git Directory is not clean" unless git.clean? raise "No chain for #{child}" unless last_record = storage.record_for(child) records = [last_record] while new_record = storage.record_for(last_record[:parent]) records << new_record last_record = new_record end records.reverse.each do |record| rebase(record[:child]) end end |