Class: Git::ExecutionContext::Repository Private

Inherits:
Git::ExecutionContext show all
Defined in:
lib/git/execution_context/repository.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.

Execution context for repository-bound git commands

Manages the git environment for commands that operate within an existing repository — setting GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, and GIT_SSH — and prepending --git-dir / --work-tree to every git invocation via #global_opts.

Construction

Use Repository.from_hash to build from a configuration hash:

context = Git::ExecutionContext::Repository.from_hash(repository: '/repo/.git', ...)

Examples:

Build from a configuration hash

context = Git::ExecutionContext::Repository.from_hash(
  repository: '/path/to/.git',
  working_directory: '/path/to'
)

Constant Summary

Constants inherited from Git::ExecutionContext

COMMAND_CAPTURING_ARG_DEFAULTS, COMMAND_STREAMING_ARG_DEFAULTS, STATIC_GLOBAL_OPTS

Instance Attribute Summary collapse

Attributes inherited from Git::ExecutionContext

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Git::ExecutionContext

#binary_path, #command_capturing, #command_streaming, #env_overrides, #git_ssh, #git_version

Constructor Details

#initialize(git_dir:, git_work_dir: nil, git_index_file: nil, binary_path: :use_global_config, git_ssh: :use_global_config, logger: nil) ⇒ Repository

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

Creates a new repository execution context

Examples:

Create with required git_dir

Git::ExecutionContext::Repository.new(git_dir: '/path/to/.git')

Parameters:

  • git_dir (String, nil)

    path to the .git directory

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

    path to the working tree

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

    path to the index file

  • binary_path (String, :use_global_config) (defaults to: :use_global_config)

    path to the git binary

    Give :use_global_config (the default) to use Git::Config.instance.binary_path.

    Passing nil raises ArgumentError — there is no "unset the binary" semantic.

  • git_ssh (String, nil, :use_global_config) (defaults to: :use_global_config)

    the SSH wrapper path

    Give nil to unset GIT_SSH, or :use_global_config (default) to use Git::Config.instance.git_ssh.

  • logger (Logger, nil) (defaults to: nil)

    the logger to use in the CommandLine layer

    Give nil to use a null logger (Logger.new(nil)).

Raises:

  • (ArgumentError)

    if binary_path is nil



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/git/execution_context/repository.rb', line 88

def initialize( # rubocop:disable Metrics/ParameterLists
  git_dir:,
  git_work_dir: nil,
  git_index_file: nil,
  binary_path: :use_global_config,
  git_ssh: :use_global_config,
  logger: nil
)
  super(binary_path: binary_path, git_ssh: git_ssh, logger: logger)
  @git_dir = git_dir
  @git_work_dir = git_work_dir
  @git_index_file = git_index_file
end

Instance Attribute Details

#git_dirString? (readonly)

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

Returns path to the .git directory.

Returns:

  • (String, nil)

    path to the .git directory



103
104
105
# File 'lib/git/execution_context/repository.rb', line 103

def git_dir
  @git_dir
end

#git_index_fileString? (readonly)

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

Returns path to the index file.

Returns:

  • (String, nil)

    path to the index file



109
110
111
# File 'lib/git/execution_context/repository.rb', line 109

def git_index_file
  @git_index_file
end

#git_work_dirString? (readonly)

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

Returns path to the working tree.

Returns:

  • (String, nil)

    path to the working tree



106
107
108
# File 'lib/git/execution_context/repository.rb', line 106

def git_work_dir
  @git_work_dir
end

Class Method Details

.from_hash(base_hash, logger: nil) ⇒ Git::ExecutionContext::Repository

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

Creates a Repository context from a Hash

Expected keys: :repository, :working_directory, :index, :git_ssh, :binary_path

Examples:

Build from a configuration hash

context = Git::ExecutionContext::Repository.from_hash(
  repository: '/path/to/.git',
  working_directory: '/path/to'
)

Parameters:

  • base_hash (Hash)

    the hash of repository configuration values

  • logger (Logger, nil) (defaults to: nil)

    logger forwarded to the CommandLine layer; nil uses a null logger (see Git::ExecutionContext#initialize)

Returns:



47
48
49
50
51
52
53
54
55
56
# File 'lib/git/execution_context/repository.rb', line 47

def self.from_hash(base_hash, logger: nil)
  new(
    git_dir: base_hash[:repository],
    git_index_file: base_hash[:index],
    git_work_dir: base_hash[:working_directory],
    git_ssh: base_hash.fetch(:git_ssh, :use_global_config),
    binary_path: base_hash.fetch(:binary_path, :use_global_config),
    logger: logger
  )
end

Instance Method Details

#dup_with(**overrides) ⇒ Git::ExecutionContext::Repository

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

Returns a new instance with the same configuration, applying overrides

Uses raw stored values for binary_path, git_ssh, and logger so that :use_global_config sentinels are preserved across rebuilds and future changes to Git.configure continue to take effect.

Parameters:

  • overrides (Hash)

    keyword arguments to override in the new instance

Returns:



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/git/execution_context/repository.rb', line 123

def dup_with(**overrides)
  self.class.new(
    git_dir: @git_dir,
    git_work_dir: @git_work_dir,
    git_index_file: @git_index_file,
    binary_path: @binary_path,
    git_ssh: @git_ssh,
    logger: @logger,
    **overrides
  )
end