Class: Git::ExecutionContext::Repository Private
- Inherits:
-
Git::ExecutionContext
- Object
- Git::ExecutionContext
- Git::ExecutionContext::Repository
- 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
Prefer the factory class methods over new when building from a
Base object or a hash:
context = Git::ExecutionContext::Repository.from_base(base) context = Git::ExecutionContext::Repository.from_hash(repository: '/repo/.git', ...)
Constant Summary
Constants inherited from Git::ExecutionContext
COMMAND_CAPTURING_ARG_DEFAULTS, COMMAND_STREAMING_ARG_DEFAULTS, STATIC_GLOBAL_OPTS
Instance Attribute Summary collapse
-
#base_object ⇒ Git::Base?
readonly
private
Originating base object.
-
#git_dir ⇒ String?
readonly
private
Path to the
.gitdirectory. -
#git_index_file ⇒ String?
readonly
private
Path to the index file.
-
#git_work_dir ⇒ String?
readonly
private
Path to the working tree.
Class Method Summary collapse
-
.from_base(base_object, logger: nil) ⇒ Git::ExecutionContext::Repository
private
Creates a Repository context from a Base instance.
-
.from_hash(base_hash, logger: nil) ⇒ Git::ExecutionContext::Repository
private
Creates a Repository context from a Hash.
Instance Method Summary collapse
-
#initialize(git_dir:, git_work_dir: nil, git_index_file: nil, base_object: nil, binary_path: :use_global_config, git_ssh: :use_global_config, logger: nil) ⇒ Repository
constructor
private
Creates a new repository execution context.
Methods inherited from Git::ExecutionContext
#binary_path, #command_capturing, #command_streaming, #git_ssh, #git_version
Constructor Details
#initialize(git_dir:, git_work_dir: nil, git_index_file: nil, base_object: 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
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/git/execution_context/repository.rb', line 118 def initialize( # rubocop:disable Metrics/ParameterLists git_dir:, git_work_dir: nil, git_index_file: nil, base_object: 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 @base_object = base_object end |
Instance Attribute Details
#base_object ⇒ Git::Base? (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 originating base object.
144 145 146 |
# File 'lib/git/execution_context/repository.rb', line 144 def base_object @base_object end |
#git_dir ⇒ String? (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.
135 136 137 |
# File 'lib/git/execution_context/repository.rb', line 135 def git_dir @git_dir end |
#git_index_file ⇒ String? (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.
141 142 143 |
# File 'lib/git/execution_context/repository.rb', line 141 def git_index_file @git_index_file end |
#git_work_dir ⇒ String? (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.
138 139 140 |
# File 'lib/git/execution_context/repository.rb', line 138 def git_work_dir @git_work_dir end |
Class Method Details
.from_base(base_object, 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 Base instance
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/git/execution_context/repository.rb', line 47 def self.from_base(base_object, logger: nil) new( git_dir: base_object.repo.to_s, git_index_file: base_object.index&.to_s, git_work_dir: base_object.dir&.to_s, base_object: base_object, git_ssh: base_object.git_ssh, binary_path: base_object.binary_path, logger: logger ) end |
.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
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/git/execution_context/repository.rb', line 77 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.key?(:git_ssh) ? base_hash[:git_ssh] : :use_global_config, binary_path: base_hash.key?(:binary_path) ? base_hash[:binary_path] : :use_global_config, logger: logger ) end |