# File lib/grit/git.rb, line 222
    def apply_patch(head_sha, patch)
      git_index = create_tempfile('index', true)

      options = {:env => {'GIT_INDEX_FILE' => git_index}, :raise => true}
      begin
        native(:read_tree, options.dup, head_sha)
        native(:apply, options.merge(:cached => true, :input => patch))
      rescue CommandFailed
        return false
      end
      native(:write_tree, :env => options[:env]).to_s.chomp!
    end