Решение на Пета задача от Веселин Стоянов

Обратно към всички решения

Към профила на Веселин Стоянов

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 17 успешни тест(а)
  • 13 неуспешни тест(а)

Код

require 'digest/sha1'
require 'time'
class ObjectStore
attr :temporary_data, :remove_data, :data, :branch
def initialize(block = nil)
@temporary_data, @remove_data, @data = {}, [], {}
branch.create('master')
branch.current_branch = 'master'
instance_eval &block if not block.nil?
end
def self.init(&block)
instance = ObjectStore.new(block)
instance
end
def add(name, object)
@temporary_data[name] = object
Operation.new("Added #{name} to stage.", true, object)
end
def commit(message)
if @temporary_data.empty? and @remove_data.empty?
Operation.new('Nothing to commit, working directory clean.', false)
else
count = @temporary_data.length + @remove_data.length
update_data
branch.log_commit(@temporary_data, @remove_data, @data, message)
@remove_data.clear
@temporary_data.clear
Operation.new("#{message}\n\t#{count} objects changed", true, head)
end
end
def update_data()
@remove_data.each { |name| @data.delete(name) }
@temporary_data.each { |name, object| @data[name] = object }
end
def remove(name)
if @data.include?(name)
@remove_data.push(name)
object = @data[name]
Operation.new("Added #{name} for removal.", true, object)
else
Operation.new("Object #{name} is not committed.", false)
end
end
def checkout(commit_hash)
commit = nil
branch.log[branch.current_branch].each do |c|
(@data = c.data and commit = c and break) if c.hash == commit_hash
end
if commit.nil?
Operation.new("Commit #{commit_hash} does not exist.", false)
else
delete_newer_commits(commit)
Operation.new("HEAD is now at #{commit_hash}.", true, commit)
end
end
def delete_newer_commits(commit)
delete, check = false, false
branch.log[branch.current_branch].delete_if do |c|
delete = true if commit.hash == c.hash
if delete and check
true
else
false
end
check = true if delete
end
end
def branch
if @branch == nil
@branch = Branch.new
end
@branch.data = @data
@branch
end
def log
if branch.log.empty?
error = "Branch #{branch.current_branch} does not have any commits yet."
Operation.new(error, false)
else
branch_log = branch.log[branch.current_branch].reverse
messages, sample = "", "Commit %s\nDate: %s\n\n\t%s\n\n"
branch_log.each { |c| messages << sample % [c.hash, c.date, c.message] }
messages.strip!
Operation.new(messages, true)
end
end
def get(name)
if @data.include?(name)
Operation.new("Found object #{name}.", true, @data[name])
else
Operation.new("Object #{name} is not committed.", false)
end
end
def head
if branch.log.empty?
error = "Branch #{branch.current_branch} does not have any commits yet."
Operation.new(error, false)
else
commit = branch.log[branch.current_branch].last
Operation.new(commit.message, true, commit)
end
end
class Commit
attr_reader :date, :message, :hash, :objects, :data
def initialize(*args)
@message, @date, @hash = args[0][0], args[0][1], args[0][2]
@added_data, @removed_data, @data = args[0][3], args[0][4], args[0][5]
@objects = @data.to_a
end
end
class Operation
attr_reader :message
attr :status, :result_text
def initialize(message, status, result_text = nil)
@message, @status, @result_text = message, status, result_text
unless result_text.nil?
define_singleton_method(:result) { @result_text }
end
end
def success?
status == true
end
def error?
status == false
end
end
class Branch
attr :branches
attr_writer :data
attr_accessor :current_branch, :log
def initialize
@branches, @log = {}, {}
@current_branch = nil
end
def create(branch_name)
if @branches.include?(branch_name)
Operation.new("Branch #{branch_name} already exists.", false)
else
@branches[branch_name] = @data
Operation.new("Created branch #{branch_name}.", true)
end
end
def checkout(branch_name)
if @branches.include?(branch_name)
@branches[@current_branch] = @data
@current_branch = branch_name
@data = @branches[@current_branch]
Operation.new("Switched to branch #{current_branch}.", true)
else
Operation.new("Branch #{branch_name} does not exist.", false)
end
end
def remove(branch_name)
if @branches.include?(branch_name)
if not branch_name == @current_branch
@branches.delete(branch_name)
Operation.new("Removed branch #{branch_name}.", true)
else
Operation.new("Cannot remove current branch.", false)
end
else
Operation.new("Branch #{branch_name} does not exist.", false)
end
end
def list
result, i, length = '', 0, @branches.length
@branches.keys.sort.each do |key|
result.concat(key == @current_branch ? "* #{key}" : " #{key}")
result.concat("\n") if not i + 1 == length and not length == 0
i += 1
end
Operation.new(result, true)
end
def log_commit(added_data, removed_data, new_data, message)
date = Time.new.strftime("%a %b %d %H:%M %Y %z")
hash = Digest::SHA1.hexdigest("#{date}#{message}")
commit_data = [message, date, hash, added_data, removed_data, new_data]
@log[@current_branch] = [] if @log[@current_branch].nil?
@log[@current_branch].push(Commit.new(commit_data))
end
end
end

Лог от изпълнението

.F..F.F.FFFF....F....F...F.FFF

Failures:

  1) ObjectStore can commit objects
     Failure/Error: expect(repo.commit("So cool!")).to be_success("So cool!\n\t2 objects changed", repo.head.result)
       expected #<ObjectStore::Operation:0x007f45c8bd23f0 @result_text=#<ObjectStore::Operation:0x007f45c8bd2620 @result_text=#<ObjectStore::Commit:0x007f45c8bd28a0 @hash="381573fc6aa4a6bb947e617a74fc4e0a5e152245", @date="Mon Jan 11 11:54 2016 +0200", @message="So cool!", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>, @status=true, @message="So cool!">, @status=true, @message="So cool!\n\t2 objects changed"> to be success "So cool!\n\t2 objects changed" and #<ObjectStore::Commit:0x007f45c8bd28a0 @hash="381573fc6aa4a6bb947e617a74fc4e0a5e152245", @date="Mon Jan 11 11:54 2016 +0200", @message="So cool!", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>
     # /tmp/d20160111-5693-q77iex/spec.rb:30:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) ObjectStore can commit changes which include only removed objects
     Failure/Error: expect(repo.commit("Removed object2")).to be_success("Removed object2\n\t1 objects changed", repo.head.result)
       expected #<ObjectStore::Operation:0x007f45c8bacba0 @result_text=#<ObjectStore::Operation:0x007f45c8bad078 @result_text=#<ObjectStore::Commit:0x007f45c8bad5f0 @hash="ff343270af7fccba0b8891061e016449606585e9", @date="Mon Jan 11 11:54 2016 +0200", @message="Removed object2", @data={"object1"=>"content1"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"]]>, @status=true, @message="Removed object2">, @status=true, @message="Removed object2\n\t1 objects changed"> to be success "Removed object2\n\t1 objects changed" and #<ObjectStore::Commit:0x007f45c8bad5f0 @hash="ff343270af7fccba0b8891061e016449606585e9", @date="Mon Jan 11 11:54 2016 +0200", @message="Removed object2", @data={"object1"=>"content1"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"]]>
     # /tmp/d20160111-5693-q77iex/spec.rb:53:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) ObjectStore can show head
     Failure/Error: expect(repo.head).to be_success("There we go", last_commit)
       expected #<ObjectStore::Operation:0x007f45c8b74728 @result_text=#<ObjectStore::Commit:0x007f45c8b74ca0 @hash="2fadbc18ad5c2b1ab1a6199dbb2de4ae5075511f", @date="Mon Jan 11 11:54 2016 +0200", @message="There we go", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>, @status=true, @message="There we go"> to be success "There we go" and #<ObjectStore::Operation:0x007f45c8b74a48 @result_text=#<ObjectStore::Commit:0x007f45c8b74ca0 @hash="2fadbc18ad5c2b1ab1a6199dbb2de4ae5075511f", @date="Mon Jan 11 11:54 2016 +0200", @message="There we go", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>, @status=true, @message="There we go">
     # /tmp/d20160111-5693-q77iex/spec.rb:69:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) ObjectStore can show log of changes for a single commit
     Failure/Error: commit_hash = Digest::SHA1.hexdigest("#{commit.date.strftime("%a %b %d %H:%M %Y %z")}#{commit.message}")
     NoMethodError:
       undefined method `date' for #<ObjectStore::Operation:0x007f45c8b65908>
     # /tmp/d20160111-5693-q77iex/spec.rb:82:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) ObjectStore can show log of changes for a single commit
     Failure/Error: commit_hash = Digest::SHA1.hexdigest("#{commit.date.strftime("%a %b %d %H:%M %Y %z")}#{commit.message}")
     NoMethodError:
       undefined method `date' for #<ObjectStore::Operation:0x007f45c8b61510>
     # /tmp/d20160111-5693-q77iex/spec.rb:91:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) ObjectStore can show log of changes for multiple commits
     Failure/Error: commit1_hash = Digest::SHA1.hexdigest("#{commit1.date.strftime(time_format)}#{commit1.message}")
     NoMethodError:
       undefined method `date' for #<ObjectStore::Operation:0x007f45c8b54770>
     # /tmp/d20160111-5693-q77iex/spec.rb:105:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) ObjectStore shows the log for the current branch only
     Failure/Error: commit1_hash = Digest::SHA1.hexdigest("#{commit1.date.strftime(time_format)}#{commit1.message}")
     NoMethodError:
       undefined method `date' for #<ObjectStore::Operation:0x007f45c8b50df0>
     # /tmp/d20160111-5693-q77iex/spec.rb:126:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) ObjectStore can switch branches
     Failure/Error: expect(repo.head).to be_success("Second commit", second_commit)
       expected #<ObjectStore::Operation:0x007f45c87cbc98 @result_text=#<ObjectStore::Commit:0x007f45c87d4690 @hash="ffeb5391d1ec154dd4a821a1aeed876cad514a0d", @date="Mon Jan 11 11:54 2016 +0200", @message="Second commit", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>, @status=true, @message="Second commit"> to be success "Second commit" and #<ObjectStore::Operation:0x007f45c87d41e0 @result_text=#<ObjectStore::Commit:0x007f45c87d4690 @hash="ffeb5391d1ec154dd4a821a1aeed876cad514a0d", @date="Mon Jan 11 11:54 2016 +0200", @message="Second commit", @data={"object1"=>"content1", "object2"=>"content2"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content2"]]>, @status=true, @message="Second commit">
     # /tmp/d20160111-5693-q77iex/spec.rb:161:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) ObjectStore can be initialized with block
     Failure/Error: expect(repo.head).to be_success("Second commit", $second_commit)
       expected #<ObjectStore::Operation:0x007f45c8715d58 @result_text=#<ObjectStore::Commit:0x007f45c87162f8 @hash="ffeb5391d1ec154dd4a821a1aeed876cad514a0d", @date="Mon Jan 11 11:54 2016 +0200", @message="Second commit", @data={"object1"=>"content1", "object2"=>"content"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content"]]>, @status=true, @message="Second commit"> to be success "Second commit" and #<ObjectStore::Operation:0x007f45c8716050 @result_text=#<ObjectStore::Commit:0x007f45c87162f8 @hash="ffeb5391d1ec154dd4a821a1aeed876cad514a0d", @date="Mon Jan 11 11:54 2016 +0200", @message="Second commit", @data={"object1"=>"content1", "object2"=>"content"}, @removed_data=[], @added_data={}, @objects=[["object1", "content1"], ["object2", "content"]]>, @status=true, @message="Second commit">
     # /tmp/d20160111-5693-q77iex/spec.rb:195:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) ObjectStore can checkout commits
     Failure/Error: expect(repo.checkout(first_commit.hash)).to be_success("HEAD is now at #{first_commit.hash}.", first_commit)
       expected #<ObjectStore::Operation:0x007f45c8634600 @result_text=nil, @status=false, @message="Commit 4382332343905947327 does not exist."> to be success "HEAD is now at 4382332343905947327." and #<ObjectStore::Operation:0x007f45c8635280 @result_text=#<ObjectStore::Commit:0x007f45c8635460 @hash="48bd765d675f355375408e84d12573236b16ddc2", @date="Mon Jan 11 11:54 2016 +0200", @message="First commit", @data={"number"=>21}, @removed_data=[], @added_data={}, @objects=[["number", 42]]>, @status=true, @message="First commit">
     # /tmp/d20160111-5693-q77iex/spec.rb:223:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) ObjectStore cannot checkout commits in empty repository
     Failure/Error: expect(repo.checkout("[not-present]")).to be_error("Commit [not-present] does not exist.")
     NoMethodError:
       undefined method `each' for nil:NilClass
     # /tmp/d20160111-5693-q77iex/solution.rb:54:in `checkout'
     # /tmp/d20160111-5693-q77iex/spec.rb:236:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) ObjectStore can show the objects in a repo after overwriting an object
     Failure/Error: expect(first_commit.objects).to match_array(["content1"])
     NoMethodError:
       undefined method `objects' for #<ObjectStore::Operation:0x007f45c85f4ca8>
     # /tmp/d20160111-5693-q77iex/spec.rb:243:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) ObjectStore can show the objects of a repo after removing an object
     Failure/Error: expect(first_commit.objects).to match_array(["content1", "content2", "content3"])
     NoMethodError:
       undefined method `objects' for #<ObjectStore::Operation:0x007f45c85d0b00>
     # /tmp/d20160111-5693-q77iex/spec.rb:259:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.02722 seconds
30 examples, 13 failures

Failed examples:

rspec /tmp/d20160111-5693-q77iex/spec.rb:26 # ObjectStore can commit objects
rspec /tmp/d20160111-5693-q77iex/spec.rb:46 # ObjectStore can commit changes which include only removed objects
rspec /tmp/d20160111-5693-q77iex/spec.rb:63 # ObjectStore can show head
rspec /tmp/d20160111-5693-q77iex/spec.rb:77 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-q77iex/spec.rb:86 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-q77iex/spec.rb:95 # ObjectStore can show log of changes for multiple commits
rspec /tmp/d20160111-5693-q77iex/spec.rb:111 # ObjectStore shows the log for the current branch only
rspec /tmp/d20160111-5693-q77iex/spec.rb:153 # ObjectStore can switch branches
rspec /tmp/d20160111-5693-q77iex/spec.rb:187 # ObjectStore can be initialized with block
rspec /tmp/d20160111-5693-q77iex/spec.rb:217 # ObjectStore can checkout commits
rspec /tmp/d20160111-5693-q77iex/spec.rb:234 # ObjectStore cannot checkout commits in empty repository
rspec /tmp/d20160111-5693-q77iex/spec.rb:239 # ObjectStore can show the objects in a repo after overwriting an object
rspec /tmp/d20160111-5693-q77iex/spec.rb:253 # ObjectStore can show the objects of a repo after removing an object

История (1 версия и 1 коментар)

Веселин обнови решението на 23.11.2015 16:19 (преди около 9 години)

+require 'digest/sha1'
+require 'time'
+
+class ObjectStore
+ attr :temporary_data, :remove_data, :data, :branch
+
+ def initialize(block = nil)
+ @temporary_data, @remove_data, @data = {}, [], {}
+ branch.create('master')
+ branch.current_branch = 'master'
+ instance_eval &block if not block.nil?
+ end
+
+ def self.init(&block)
+ instance = ObjectStore.new(block)
+ instance
+ end
+
+ def add(name, object)
+ @temporary_data[name] = object
+ Operation.new("Added #{name} to stage.", true, object)
+ end
+
+ def commit(message)
+ if @temporary_data.empty? and @remove_data.empty?
+ Operation.new('Nothing to commit, working directory clean.', false)
+ else
+ count = @temporary_data.length + @remove_data.length
+ update_data
+ branch.log_commit(@temporary_data, @remove_data, @data, message)
+ @remove_data.clear
+ @temporary_data.clear
+ Operation.new("#{message}\n\t#{count} objects changed", true, head)
+ end
+ end
+
+ def update_data()
+ @remove_data.each { |name| @data.delete(name) }
+ @temporary_data.each { |name, object| @data[name] = object }
+ end
+
+ def remove(name)
+ if @data.include?(name)
+ @remove_data.push(name)
+ object = @data[name]
+ Operation.new("Added #{name} for removal.", true, object)
+ else
+ Operation.new("Object #{name} is not committed.", false)
+ end
+ end
+
+ def checkout(commit_hash)
+ commit = nil
+ branch.log[branch.current_branch].each do |c|
+ (@data = c.data and commit = c and break) if c.hash == commit_hash
+ end
+
+ if commit.nil?
+ Operation.new("Commit #{commit_hash} does not exist.", false)
+ else
+ delete_newer_commits(commit)
+ Operation.new("HEAD is now at #{commit_hash}.", true, commit)
+ end
+ end
+
+ def delete_newer_commits(commit)
+ delete, check = false, false
+ branch.log[branch.current_branch].delete_if do |c|
+ delete = true if commit.hash == c.hash
+ if delete and check
+ true
+ else
+ false
+ end
+ check = true if delete
+ end
+ end
+
+ def branch
+ if @branch == nil
+ @branch = Branch.new
+ end
+
+ @branch.data = @data
+
+ @branch
+ end
+
+ def log
+ if branch.log.empty?
+ error = "Branch #{branch.current_branch} does not have any commits yet."
+ Operation.new(error, false)
+ else
+ branch_log = branch.log[branch.current_branch].reverse
+ messages, sample = "", "Commit %s\nDate: %s\n\n\t%s\n\n"
+ branch_log.each { |c| messages << sample % [c.hash, c.date, c.message] }
+ messages.strip!
+ Operation.new(messages, true)
+ end
+ end
+
+ def get(name)
+ if @data.include?(name)
+ Operation.new("Found object #{name}.", true, @data[name])
+ else
+ Operation.new("Object #{name} is not committed.", false)
+ end
+ end
+
+ def head
+ if branch.log.empty?
+ error = "Branch #{branch.current_branch} does not have any commits yet."
+ Operation.new(error, false)
+ else
+ commit = branch.log[branch.current_branch].last
+ Operation.new(commit.message, true, commit)
+ end
+ end
+
+ class Commit
+ attr_reader :date, :message, :hash, :objects, :data
+
+ def initialize(*args)
+ @message, @date, @hash = args[0][0], args[0][1], args[0][2]
+ @added_data, @removed_data, @data = args[0][3], args[0][4], args[0][5]
+ @objects = @data.to_a
+ end
+ end
+
+ class Operation
+ attr_reader :message
+ attr :status, :result_text
+
+ def initialize(message, status, result_text = nil)
+ @message, @status, @result_text = message, status, result_text
+
+ unless result_text.nil?
+ define_singleton_method(:result) { @result_text }
+ end
+ end
+
+ def success?
+ status == true
+ end
+
+ def error?
+ status == false
+ end
+ end
+
+ class Branch
+ attr :branches
+ attr_writer :data
+ attr_accessor :current_branch, :log
+
+ def initialize
+ @branches, @log = {}, {}
+ @current_branch = nil
+ end
+
+ def create(branch_name)
+ if @branches.include?(branch_name)
+ Operation.new("Branch #{branch_name} already exists.", false)
+ else
+ @branches[branch_name] = @data
+ Operation.new("Created branch #{branch_name}.", true)
+ end
+ end
+
+ def checkout(branch_name)
+ if @branches.include?(branch_name)
+ @branches[@current_branch] = @data
+ @current_branch = branch_name
+ @data = @branches[@current_branch]
+ Operation.new("Switched to branch #{current_branch}.", true)
+ else
+ Operation.new("Branch #{branch_name} does not exist.", false)
+ end
+ end
+
+ def remove(branch_name)
+ if @branches.include?(branch_name)
+ if not branch_name == @current_branch
+ @branches.delete(branch_name)
+ Operation.new("Removed branch #{branch_name}.", true)
+ else
+ Operation.new("Cannot remove current branch.", false)
+ end
+ else
+ Operation.new("Branch #{branch_name} does not exist.", false)
+ end
+ end
+
+ def list
+ result, i, length = '', 0, @branches.length
+ @branches.keys.sort.each do |key|
+ result.concat(key == @current_branch ? "* #{key}" : " #{key}")
+ result.concat("\n") if not i + 1 == length and not length == 0
+ i += 1
+ end
+ Operation.new(result, true)
+ end
+
+ def log_commit(added_data, removed_data, new_data, message)
+ date = Time.new.strftime("%a %b %d %H:%M %Y %z")
+ hash = Digest::SHA1.hexdigest("#{date}#{message}")
+ commit_data = [message, date, hash, added_data, removed_data, new_data]
+ @log[@current_branch] = [] if @log[@current_branch].nil?
+ @log[@current_branch].push(Commit.new(commit_data))
+ end
+ end
+end

Така и не успях да разбера защо не минава примерните тестове. Когато си тествам "ръчно", всичко си работи както е описано в условието на задачата. Ще помоля ако някой проверяващ прегледа решението ми, да ме насочи къде е проблемът.