Class: FakeGit::CommitTree

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_git/commit_tree.rb

Defined Under Namespace

Classes: TypeError

Instance Method Summary collapse

Instance Method Details

#call(*args) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fake_git/commit_tree.rb', line 6

def call(*args)
  # make sure that the object exists
  obj = FakeGit::FetchObject.new.call(args.first)

  raise TypeError.new("#{args.first} is not a tree") if obj.type != "tree"

  commit = FakeGit::Priv::Object.new(
    type: "commit",
    message: $OPTIONS[:commit_message],
    tree: obj.index,
    index: Digest::SHA1.hexdigest(obj.index), # just hash the index of the tree
  )

  commit.write!
  FakeGit::UpdateRef.new.call(commit.index)
end