Class: Git::Repository
- Inherits:
-
Object
- Object
- Git::Repository
- Extended by:
- Factories
- Includes:
- Configuring, Branching, Committing, Configuring, ContextHelpers, Diffing, Inspecting, Logging, Maintenance, Merging, ObjectOperations, RemoteOperations, Staging, Stashing, StatusOperations, WorktreeOperations
- Defined in:
- lib/git/repository.rb,
lib/git/repository/diffing.rb,
lib/git/repository/logging.rb,
lib/git/repository/merging.rb,
lib/git/repository/staging.rb,
lib/git/repository/stashing.rb,
lib/git/repository/branching.rb,
lib/git/repository/factories.rb,
lib/git/repository/committing.rb,
lib/git/repository/inspecting.rb,
lib/git/repository/configuring.rb,
lib/git/repository/maintenance.rb,
lib/git/repository/path_resolver.rb,
lib/git/repository/shared_private.rb,
lib/git/repository/context_helpers.rb,
lib/git/repository/object_operations.rb,
lib/git/repository/remote_operations.rb,
lib/git/repository/status_operations.rb,
lib/git/repository/worktree_operations.rb
Overview
The main public interface for interacting with a Git repository
Git::Repository is the orchestration layer for all git operations. It acts
as the glue between the user-facing API and the underlying components, but
contains minimal domain logic itself. For each operation it:
- Pre-processes arguments — transforms user-provided values into forms suitable for the command layer (e.g. path expansion, option normalization, Ruby-idiomatic defaults, deprecation handling, input validation).
- Calls commands — invokes one or more
Git::Commands::*classes via the injectedGit::ExecutionContext::Repository. - Builds rich return values — passes raw command output through
Git::Parsers::*classes and result-class factory methods to assemble the meaningful Ruby objects the caller expects.
Some operations are genuinely one-line delegators when no pre/post-processing is
needed (e.g. add, reset), but many are short orchestration sequences that
coordinate argument preparation, one or more command calls, and result assembly.
Facade methods are organized into focused modules under lib/git/repository/
(e.g. Staging) and included into this class.
Defined Under Namespace
Modules: Branching, Committing, Configuring, ContextHelpers, Diffing, Factories, Inspecting, Logging, Maintenance, Merging, ObjectOperations, PathResolver, RemoteOperations, Staging, Stashing, StatusOperations, WorktreeOperations
Instance Attribute Summary collapse
-
#execution_context ⇒ Git::ExecutionContext::Repository
readonly
private
The execution context used to run git commands for this repository.
Attributes included from Branching
Instance Method Summary collapse
-
#binary_path ⇒ String, :use_global_config
private
The path to the git binary.
-
#dir ⇒ Pathname?
Returns the root of the working tree, or
nilfor a bare repository. -
#git_dir ⇒ String?
private
The git directory path.
-
#git_index_file ⇒ String?
private
The index file path.
-
#git_ssh ⇒ String?
private
The SSH wrapper path.
-
#git_version(timeout: nil) ⇒ Git::Version
private
The installed git version.
-
#git_work_dir ⇒ String?
private
The working directory path.
-
#index ⇒ Pathname?
Returns the git index file.
-
#initialize(execution_context:) ⇒ Repository
constructor
A new instance of Repository.
-
#lib ⇒ self
private
Returns
selfafter emitting a deprecation warning. -
#repo ⇒ Pathname?
Returns the repository (
.git) directory. -
#repo_size ⇒ Integer
Returns the size of the repository directory in bytes.
Methods included from Factories
Methods included from WorktreeOperations
#worktree, #worktree_add, #worktree_prune, #worktree_remove, #worktrees, #worktrees_all
Methods included from StatusOperations
#empty?, #ls_files, #no_commits?, #status, #untracked_files
Methods included from Stashing
#stash_apply, #stash_clear, #stash_list, #stash_save, #stashes_all
Methods included from Staging
#add, #apply, #apply_mail, #clean, #ignored_files, #mv, #read_tree, #reset, #reset_hard, #rm
Methods included from RemoteOperations
#add_remote, #config_remote, #fetch, #ls_remote, #pull, #push, #remote, #remote_add, #remote_remove, #remote_set_branches, #remote_set_url, #remotes, #remove_remote, #set_remote_url
Methods included from ObjectOperations
#add_tag, #archive, #cat_file_commit, #cat_file_contents, #cat_file_size, #cat_file_tag, #cat_file_type, #delete_tag, #full_tree, #gblob, #gcommit, #grep, #gtree, #ls_tree, #name_rev, #object, #rev_parse, #tag, #tag_add, #tag_delete, #tag_sha, #tags, #tree_depth
Methods included from Merging
#conflicts, #each_conflict, #merge, #merge_base, #revert, #unmerged
Methods included from Maintenance
Methods included from Logging
Methods included from Inspecting
Methods included from Diffing
#diff, #diff_files, #diff_full, #diff_index, #diff_numstat, #diff_path_status, #diff_stats
Methods included from Configuring
Methods included from Committing
#commit, #commit_all, #commit_tree, #write_and_commit_tree, #write_tree
Methods included from ContextHelpers
#chdir, #set_index, #set_working, #with_index, #with_temp_index, #with_temp_working, #with_working
Methods included from Branching
#branch, #branch?, #branch_contains, #branch_delete, #branch_new, #branches, #branches_all, #change_head_branch, #checkout, #checkout_file, #checkout_index, #current_branch, #current_branch_state, #is_branch?, #is_local_branch?, #is_remote_branch?, #local_branch?, #remote_branch?, #update_ref
Methods included from Configuring
#config_add, #config_get, #config_get_all, #config_get_colorbool, #config_get_regexp, #config_get_urlmatch, #config_list, #config_remove_section, #config_rename_section, #config_replace_all, #config_set, #config_unset, #config_unset_all
Constructor Details
#initialize(execution_context:) ⇒ Repository
Returns a new instance of Repository.
81 82 83 84 85 |
# File 'lib/git/repository.rb', line 81 def initialize(execution_context:) raise ArgumentError, 'execution_context must not be nil' if execution_context.nil? @execution_context = execution_context end |
Instance Attribute Details
#execution_context ⇒ Git::ExecutionContext::Repository (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 the execution context used to run git commands for this repository.
74 75 76 |
# File 'lib/git/repository.rb', line 74 def execution_context @execution_context end |
Instance Method Details
#binary_path ⇒ String, :use_global_config
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 the path to the git binary.
169 |
# File 'lib/git/repository.rb', line 169 def binary_path = execution_context.binary_path |
#dir ⇒ Pathname?
Returns the root of the working tree, or nil for a bare repository
94 95 96 97 |
# File 'lib/git/repository.rb', line 94 def dir working_dir = execution_context.git_work_dir working_dir && Pathname.new(working_dir) end |
#git_dir ⇒ String?
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 the git directory path.
144 |
# File 'lib/git/repository.rb', line 144 def git_dir = execution_context.git_dir |
#git_index_file ⇒ String?
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 the index file path.
154 |
# File 'lib/git/repository.rb', line 154 def git_index_file = execution_context.git_index_file |
#git_ssh ⇒ String?
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 the SSH wrapper path.
164 |
# File 'lib/git/repository.rb', line 164 def git_ssh = execution_context.git_ssh |
#git_version(timeout: nil) ⇒ Git::Version
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 the installed git version.
159 |
# File 'lib/git/repository.rb', line 159 def git_version(timeout: nil) = execution_context.git_version(timeout: timeout) |
#git_work_dir ⇒ String?
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 the working directory path.
149 |
# File 'lib/git/repository.rb', line 149 def git_work_dir = execution_context.git_work_dir |
#index ⇒ Pathname?
Returns the git index file
118 119 120 121 |
# File 'lib/git/repository.rb', line 118 def index index_file = execution_context.git_index_file index_file && Pathname.new(index_file) end |
#lib ⇒ self
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 self after emitting a deprecation warning.
Legacy callers that used git.lib.some_method can migrate to calling the
facade method directly on the repository object. This shim will be removed
in v6.0.0.
133 134 135 136 137 138 139 |
# File 'lib/git/repository.rb', line 133 def lib Git::Deprecation.warn( 'Git::Repository#lib is deprecated and will be removed in v6.0.0. ' \ 'Use the repository object directly.' ) self end |
#repo ⇒ Pathname?
Returns the repository (.git) directory
106 107 108 109 |
# File 'lib/git/repository.rb', line 106 def repo repository = execution_context.git_dir repository && Pathname.new(repository) end |
#repo_size ⇒ Integer
Returns the size of the repository directory in bytes
Sums the sizes of every regular file under the repository (.git)
directory in a single traversal. Symbolic links are not followed, so files
that physically live outside the repository (reached through a symlinked
directory) are never counted. Files that disappear mid-traversal are
silently skipped.
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/git/repository.rb', line 184 def repo_size repository = repo return 0 unless repository&.directory? total = 0 Find.find(repository.to_s) do |path| stat = File.lstat(path) total += stat.size if stat.file? rescue Errno::ENOENT next end total end |