def apply_patch(options={}, head_sha=nil, patch=nil)
      options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash)
      options = options.dup
      options[:env] &&= options[:env].dup
      options[:raise] = true

      git_index = create_tempfile('index', true)
      (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)

      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
def apply_patch(options={}, head_sha=nil, patch=nil)
      options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash)
      options = options.dup
      options[:env] &&= options[:env].dup
      options[:raise] = true

      git_index = create_tempfile('index', true)
      (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)

      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
Applies the given patch against the given SHA of the current repo.

 options  - grit command hash
 head_sha - String SHA or ref to apply the patch to.
 patch    - The String patch to apply.  Get this from #get_patch.

 Returns the String Tree SHA on a successful patch application, or false.