Method: Metaverse::Repo#load_state

Defined in:
lib/metaverse/repo.rb

#load_state(prefix, state, remote = nil, should_create_branch = false) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/metaverse/repo.rb', line 111

def load_state prefix, state, remote = nil, should_create_branch = false
  ref_name = "refs/meta"
  ref_name += remote.nil? ? "/local" : "/remotes/#{remote}"
  ref_name += "/#{prefix}/#{state}"
  if should_create_branch
    branch_name = "#{prefix}/#{state}"
    # TODO: Decide what to do when a branch exists previous. Should we :
    # - Replace it's ref by the saved state ? ( We lose the previous branch reference)
    # - Load it as it is ( We may get an inconsistent state since the branch could point to a different commit than the state reference )
    if @repo.branches[branch_name].nil?
      puts "Creating branch #{branch_name} based on #{ref_name}"
      @repo.create_branch branch_name, ref_name
    end
    return checkout branch_name
  end
  checkout ref_name
end