Method: Rugged::Repository#checkout

Defined in:
lib/rugged/repository.rb

#checkout(target, options = {}) ⇒ Object

Checkout the specified branch, reference or commit.

target - A revparse spec for the branch, reference or commit to check out. options - Options passed to #checkout_tree.

[View source]

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rugged/repository.rb', line 29

def checkout(target, options = {})
  options[:strategy] ||= :safe
  options.delete(:paths)

  return checkout_head(**options) if target == "HEAD"

  if target.kind_of?(Rugged::Branch)
    branch = target
  else
    branch = branches[target]
  end

  if branch
    self.checkout_tree(branch.target, **options)

    if branch.remote?
      references.create("HEAD", branch.target_id, force: true)
    else
      references.create("HEAD", branch.canonical_name, force: true)
    end
  else
    commit = Commit.lookup(self, self.rev_parse_oid(target))
    references.create("HEAD", commit.oid, force: true)
    self.checkout_tree(commit, **options)
  end
end