Class: Git::Commands::Apply Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/apply.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-apply/2.53.0

Implements git apply to apply a patch to files and/or to the index

Reads the supplied diff output (a patch) and applies it to files. Without options, the command applies the patch only to working tree files. With index: true, the patch is also applied to the index. With cached: true, the patch is only applied to the index.

Examples:

Typical usage

apply = Git::Commands::Apply.new(execution_context)
apply.call('fix.patch')
apply.call('fix.patch', cached: true)
apply.call('fix.patch', check: true)
apply.call('fix.patch', reverse: true)

See Also:

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(*patch, **options) ⇒ Git::CommandLineResult

Apply one or more patch files to the working tree or index

Parameters:

  • patch (Array<String>)

    zero or more patch file paths to apply; omit to read from standard input

  • options (Hash)

    command options

Options Hash (**options):

  • :stat (Boolean, nil) — default: nil

    show diffstat for the input instead of applying

    Turns off apply mode.

  • :numstat (Boolean, nil) — default: nil

    show numeric diffstat for the input instead of applying

    Turns off apply mode. Output is in machine-friendly decimal format.

  • :summary (Boolean, nil) — default: nil

    show a condensed summary of extended header information instead of applying

    Turns off apply mode.

  • :check (Boolean, nil) — default: nil

    check whether the patch applies cleanly without modifying any files

    Turns off apply mode.

  • :index (Boolean, nil) — default: nil

    apply the patch to both the index and the working tree

  • :intent_to_add (Boolean, nil) — default: nil

    mark new files added by the patch for later addition to the index

    Alias: :N

  • :three_way (Boolean, nil) — default: nil

    attempt a 3-way merge if the patch does not apply cleanly (--3way)

  • :ours (Boolean, nil) — default: nil

    resolve 3-way conflicts by favouring our side of the conflict

    Requires :three_way.

  • :theirs (Boolean, nil) — default: nil

    resolve 3-way conflicts by favouring their side of the conflict

    Requires :three_way.

  • :union (Boolean, nil) — default: nil

    resolve 3-way conflicts by including both sides of the conflict

    Requires :three_way.

  • :apply (Boolean, nil) — default: nil

    re-enable the apply step even when a "turns off apply" flag such as :stat is also given

  • :no_add (Boolean, nil) — default: nil

    ignore additions made by the patch; apply only the deletions

  • :build_fake_ancestor (String) — default: nil

    path to a temporary index file for building a fake ancestor from the embedded blob identities in the patch

  • :reverse (Boolean, nil) — default: nil

    apply the patch in reverse

    Alias: :R

  • :allow_binary_replacement (Boolean, nil) — default: nil

    allow binary patch application (no-op in Git 2.28+)

    Alias: :binary

  • :reject (Boolean, nil) — default: nil

    leave rejected hunks in .rej files instead of aborting

  • :z (Boolean, nil) — default: nil

    use NUL-terminated output for --numstat pathnames (-z)

  • :p (Integer) — default: nil

    strip this many leading path components from traditional diff paths (-p<n>)

  • :C (Integer) — default: nil

    require at least this many lines of surrounding context before and after each change (-C<n>)

  • :unidiff_zero (Boolean, nil) — default: nil

    bypass context-line safety checks for diffs generated with --unified=0

  • :inaccurate_eof (Boolean, nil) — default: nil

    work around diffs that do not correctly detect a missing newline at end of file

  • :recount (Boolean, nil) — default: nil

    infer hunk sizes from the patch content rather than trusting the hunk header counts

  • :cached (Boolean, nil) — default: nil

    apply the patch only to the index without touching the working tree

  • :ignore_space_change (Boolean, nil) — default: nil

    ignore changes in the amount of whitespace in context lines

  • :ignore_whitespace (Boolean, nil) — default: nil

    ignore all whitespace differences in context lines

  • :whitespace (String) — default: nil

    whitespace error handling mode: 'nowarn', 'warn', 'fix', 'error', or 'error-all'

  • :exclude (String) — default: nil

    skip changes to files matching this path pattern

  • :include (String) — default: nil

    apply changes only to files matching this path pattern

  • :directory (String) — default: nil

    prepend this root to all filenames in the patch

  • :verbose (Boolean, nil) — default: nil

    report progress to stderr

    Alias: :v

  • :quiet (Boolean, nil) — default: nil

    suppress stderr output

    Alias: :q

  • :unsafe_paths (Boolean, nil) — default: nil

    override the safety check that rejects patches affecting paths outside the working area

  • :allow_empty (Boolean, nil) — default: nil

    do not return an error for patches containing no diff

  • :chdir (String) — default: nil

    change to this directory before running git; not passed to the git CLI

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/apply.rb', line 93