Module: Git::PathResolver Private
- Defined in:
- lib/git/path_resolver.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Resolves and normalizes the filesystem paths that locate a Git repository
PathResolver is the single home for the path-resolution logic used by the
Git factory methods (open, bare, init, and clone).
It computes the absolute working-directory, repository (.git), and index
paths from the caller-supplied values, following the same rules Git itself
uses (including gitdir-pointer files for submodules and linked worktrees).
A relative path given by the caller is expanded against the process working
directory, as git does for a path on its command line. Only the defaults are
derived from the layout: an omitted repository is <working_directory>/.git
and an omitted index is <repository>/index.
Constant Summary collapse
- WORKING_DIRECTORY_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The Error message when a working directory path cannot be expanded
'Failed to resolve the working directory'- REPOSITORY_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The Error message when a repository directory path cannot be expanded
'Failed to resolve the repository directory'- INDEX_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The Error message when an index file path cannot be expanded
'Failed to resolve the index file'- CHDIR_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The Error message when the
:chdiroption ofGit.clonecannot be expanded 'Failed to resolve the chdir directory'
Class Method Summary collapse
-
.expand_path(path, message, base: nil) ⇒ String
private
Expand a path the way a shell prompt would before git runs.
-
.resolve_paths(working_directory: nil, repository: nil, index: nil, bare: false) ⇒ Hash{Symbol => (String, nil)}
private
Resolve and normalize the paths that locate a Git repository.
-
.root_of_worktree(working_dir, binary_path: :use_global_config, git_ssh: :use_global_config) ⇒ String
private
Find the root of the working tree that contains
working_dir.
Class Method Details
.expand_path(path, message, base: nil) ⇒ 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.
Expand a path the way a shell prompt would before git runs
Follows File.expand_path: ~ is the home directory, a relative path is
joined onto base (or onto the process working directory when base is
nil), . and .. are normalized, and an absolute path is unchanged.
270 271 272 |
# File 'lib/git/path_resolver.rb', line 270 def (path, , base: nil) Git::SystemCallGuard.call() { File.(path || '.', base) } end |
.resolve_paths(working_directory: nil, repository: nil, index: nil, bare: false) ⇒ Hash{Symbol => (String, nil)}
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.
Resolve and normalize the paths that locate a Git repository
Returns a new hash containing the resolved absolute paths for:
* `:working_directory` — the working tree root (`nil` for bare repos)
* `:repository` — the `.git` directory
* `:index` — the index file
This method does not mutate any inputs.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/git/path_resolver.rb', line 67 def resolve_paths(working_directory: nil, repository: nil, index: nil, bare: false) working_dir = resolve_working_directory(working_directory, bare: ) repo_path = resolve_repository(repository, working_dir) index_path = resolve_index(index, repo_path) { working_directory: working_dir, repository: repo_path, index: index_path } end |
.root_of_worktree(working_dir, binary_path: :use_global_config, git_ssh: :use_global_config) ⇒ 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.
Find the root of the working tree that contains working_dir
Runs git rev-parse --show-toplevel from working_dir to locate the
top-level directory of the working tree.
106 107 108 109 110 111 |
# File 'lib/git/path_resolver.rb', line 106 def root_of_worktree(working_dir, binary_path: :use_global_config, git_ssh: :use_global_config) = (working_dir, 'Failed to expand the working directory path') raise ArgumentError, "'#{working_dir}' does not exist or is not a directory" unless Dir.exist?() execute_rev_parse_toplevel(, binary_path: binary_path, git_ssh: git_ssh) end |