Class: GitChain::Chain

Inherits:
Struct
  • Object
show all
Defined in:
lib/git_chain/chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gitObject

Returns the value of attribute git

Returns:

  • (Object)

    the current value of git



1
2
3
# File 'lib/git_chain/chain.rb', line 1

def git
  @git
end

#storageObject

Returns the value of attribute storage

Returns:

  • (Object)

    the current value of 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