Gazler/githug

View on GitHub
levels/restore.rb

Summary

Maintainability
A
0 mins
Test Coverage
difficulty 4
description "You decided to delete your latest commit by running `git reset --hard HEAD^` (not a smart thing to do). Now you changed your mind and want that commit back. Restore the deleted commit."

setup do
  repo.init
  FileUtils.touch 'file1'
  repo.add        'file1'
  repo.commit_all 'Initial commit'
  system "git branch -m master"

  FileUtils.touch 'file2'
  repo.add        'file2'
  repo.commit_all 'First commit'

  FileUtils.touch 'file3'
  repo.add        'file3'
  repo.commit_all 'Restore this commit'

  repo.git.native :reset, { "hard" => true }, 'HEAD^'
end

solution do
  return false unless File.exists?('file3')
  true
end

hint do
  puts "The commit is still floating around somewhere. Have you checked out `git reflog`?"
end