Module: Git::Repository::StatusOperations Private
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/status_operations.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.
Facade methods for repository-status operations
Provides methods for querying the state of the repository: checking whether any commits exist, listing untracked working-tree files, and listing files tracked in the index.
Included by Git::Repository.
Instance Method Summary collapse
-
#ls_files(location = nil) ⇒ Hash{String => Hash}
private
List all files tracked in the index.
-
#no_commits? ⇒ Boolean
private
Returns
trueif the repository has no commits yet. -
#status_info ⇒ Git::StatusInfo
private
Returns a StatusInfo describing the index and working tree state.
-
#untracked_files ⇒ Array<String>
private
List all files in the working tree that are not tracked by git.
Instance Method Details
#ls_files(location = nil) ⇒ Hash{String => Hash}
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.
List all files tracked in the index
Runs git ls-files --stage under the given location and returns a
hash keyed by file path with per-file index metadata.
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/git/repository/status_operations.rb', line 138 def ls_files(location = nil) location ||= '.' {}.tap do |files| Git::Commands::LsFiles.new(@execution_context).call(location, stage: true).stdout.split("\n").each do |line| info, file = Private.split_status_line(line) mode, sha, stage = info.split files[file] = { path: file, mode_index: mode, sha_index: sha, stage: stage } end end end |
#no_commits? ⇒ Boolean
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 true if the repository has no commits yet
Checks whether HEAD can be resolved to a commit object. A brand-new
repository (or one created with git checkout --orphan) where no commit
has been made yet will have no commits.
38 39 40 41 42 43 44 45 46 |
# File 'lib/git/repository/status_operations.rb', line 38 def no_commits? Git::Commands::RevParse.new(@execution_context).call('HEAD', verify: true) false rescue Git::FailedError => e raise unless e.result.status.exitstatus == 128 && e.result.stderr == 'fatal: Needed a single revision' true end |
#status_info ⇒ Git::StatusInfo
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 StatusInfo describing the index and working tree state
Runs git status in porcelain v2 format with NUL-separated entries and
every untracked file listed individually, then reads core.ignoreCase
as a boolean so that the path predicates on the result compare paths the
way git does in this repository. Every entry type git reports is
represented, including renames, copies, and merge conflicts. Clean
tracked paths are not reported by git status, so they are absent from
the result; #ls_files lists them.
102 103 104 105 106 107 108 109 |
# File 'lib/git/repository/status_operations.rb', line 102 def status_info result = Git::Commands::Status.new(@execution_context).call( porcelain: 'v2', z: true, untracked_files: 'all' ) files = Git::Parsers::Status.parse(result.stdout) ignore_case = config_get('core.ignoreCase', type: 'bool')&.value == 'true' Git::StatusInfo.new(files: files, ignore_case: ignore_case) end |
#untracked_files ⇒ Array<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.
List all files in the working tree that are not tracked by git
Runs git ls-files --others --exclude-standard from the working tree
root and returns an array of repository-relative file paths. Files that
match .gitignore or other standard exclusion rules are omitted.
65 66 67 68 69 |
# File 'lib/git/repository/status_operations.rb', line 65 def untracked_files Git::Commands::LsFiles.new(@execution_context).call( others: true, exclude_standard: true, chdir: @execution_context.git_work_dir ).stdout.split("\n").map { |f| Private.unescape_quoted_path(f) } end |