Class: Git::Commands::Checkout::Files Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/checkout/files.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-checkout/2.53.0

Implements the git checkout command for restoring working tree files

This command replaces files in the working tree with versions from the index (when tree_ish is nil) or a specified tree-ish (commit, branch, tag, etc.).

Examples:

Restore working tree files

files = Git::Commands::Checkout::Files.new(execution_context)
files.call(pathspec: ['lib/foo.rb'])                             # from the index
files.call('HEAD~1', pathspec: ['lib/foo.rb'])                   # from a specific commit
files.call('main', pathspec: %w[lib/foo.rb lib/bar.rb])          # from a branch
files.call(pathspec: ['conflicted.txt'], ours: true)             # resolve conflict (ours)
files.call('main', pathspec_from_file: 'paths.txt')              # paths from a file

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(tree_ish = nil, **options) ⇒ Git::CommandLineResult

Execute the git checkout command for restoring files

Parameters:

  • tree_ish (String, nil) (defaults to: nil)

    The commit, branch, or tree to restore files from

    When nil, files are restored from the index

  • options (Hash)

    command options

Options Hash (**options):

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

    ignore unmerged entries

    Alias: :f

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

    for unmerged paths, check out stage #2 (our version)

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

    for unmerged paths, check out stage #3 (their version)

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

    recreate the conflicted merge in the specified paths; cannot be used when checking out from a tree-ish

    Alias: :m

  • :conflict (String) — default: nil

    conflict marker style; valid values are 'merge', 'diff3', and 'zdiff3'

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

    never remove files from the index or working tree that are not present in the tree-ish (--overlay)

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

    remove files not present in the tree-ish from the index and working tree (--no-overlay)

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

    in sparse checkout mode, ignore sparse patterns and update all files matched by pathspec

  • :pathspec_from_file (String) — default: nil

    read pathspec from this file; pass '-' to read from stdin

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

    with :pathspec_from_file, separate pathspec elements with NUL instead of newline

  • :pathspec (Array<String>, String) — default: nil

    the files or directories to restore

  • :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/checkout/files.rb', line 50