def check_applies(options={}, head_sha=nil, applies_sha=nil)
      options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash)
      options = options.dup
      options[:env] &&= options[:env].dup

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

      status = 0
      begin
        native(:read_tree, options.dup, head_sha)
        stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha)
        native(:apply, options.merge(:check => true, :cached => true, :input => stdin))
      rescue CommandFailed => fail
        status += fail.exitstatus
      end
      status
    end
def check_applies(options={}, head_sha=nil, applies_sha=nil)
      options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash)
      options = options.dup
      options[:env] &&= options[:env].dup

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

      status = 0
      begin
        native(:read_tree, options.dup, head_sha)
        stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha)
        native(:apply, options.merge(:check => true, :cached => true, :input => stdin))
      rescue CommandFailed => fail
        status += fail.exitstatus
      end
      status
    end
Checks if the patch of a commit can be applied to the given head.

 options     - grit command options hash
 head_sha    - String SHA or ref to check the patch against.
 applies_sha - String SHA of the patch.  The patch itself is retrieved
               with #get_patch.

 Returns 0 if the patch applies cleanly (according to `git apply`), or
 an Integer that is the sum of the failed exit statuses.