Module: Git::Repository::Staging
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/staging.rb
Overview
Facade methods for staging-area operations: adding, resetting, moving, removing, and cleaning files
Included by Git::Repository.
Instance Method Summary collapse
-
#add(paths = '.', **options) ⇒ String
Update the index with the current content found in the working tree.
-
#apply(file) ⇒ String?
Apply a patch file to the working tree.
-
#apply_mail(file) ⇒ String?
Apply a series of patches from a mailbox file to the current branch.
-
#clean(opts = {}) ⇒ String
Remove untracked files from the working tree.
-
#ignored_files ⇒ Array<String>
List the files in the working tree that are ignored by git.
-
#mv(source, destination, options = {}) ⇒ String
Move or rename a file, directory, or symlink in the working tree.
-
#read_tree(treeish, opts = {}) ⇒ String
Read tree information into the index.
-
#reset(commitish = nil, opts = {}) ⇒ String
Reset the current HEAD to a specified state.
-
#reset_hard(commitish = nil, opts = {}) ⇒ String
deprecated
Deprecated.
Use #reset with
hard: trueinstead.@example Hard reset to HEAD repo.reset_hard
@example Hard reset to a specific commit repo.reset_hard('HEAD~1')
-
#rm(path = '.', opts = {}) ⇒ String
(also: #remove)
Remove file(s) from the working tree and the index.
Instance Method Details
#add(paths = '.', **options) ⇒ String
Update the index with the current content found in the working tree
59 60 61 62 |
# File 'lib/git/repository/staging.rb', line 59 def add(paths = '.', **) SharedPrivate.assert_valid_opts!(ADD_ALLOWED_OPTS, **) Git::Commands::Add.new(@execution_context).call(*Array(paths), **).stdout end |
#apply(file) ⇒ String?
Apply a patch file to the working tree
Reads the unified diff in file and applies it to the working tree via
git apply. If file does not exist, the method returns nil without
calling git — preserving the 4.x Git::Base#apply no-op contract.
141 142 143 144 145 |
# File 'lib/git/repository/staging.rb', line 141 def apply(file) return unless File.exist?(file) Git::Commands::Apply.new(@execution_context).call(file, chdir: @execution_context.git_work_dir).stdout end |
#apply_mail(file) ⇒ String?
Apply a series of patches from a mailbox file to the current branch
Reads the mbox-format file in file and applies the patches via
git am. If file does not exist, the method returns nil without
calling git — preserving the 4.x Git::Base#apply_mail no-op contract.
164 165 166 167 168 |
# File 'lib/git/repository/staging.rb', line 164 def apply_mail(file) return unless File.exist?(file) Git::Commands::Am::Apply.new(@execution_context).call(file, chdir: @execution_context.git_work_dir).stdout end |
#clean(opts = {}) ⇒ String
Remove untracked files from the working tree
382 383 384 385 386 |
# File 'lib/git/repository/staging.rb', line 382 def clean(opts = {}) opts = Private.(opts) SharedPrivate.assert_valid_opts!(CLEAN_ALLOWED_OPTS, **opts) Git::Commands::Clean.new(@execution_context).call(**opts).stdout end |
#ignored_files ⇒ Array<String>
List the files in the working tree that are ignored by git
Runs git ls-files --others --ignored --exclude-standard and returns the
ignored files as repository-relative paths.
404 405 406 407 408 |
# File 'lib/git/repository/staging.rb', line 404 def ignored_files Git::Commands::LsFiles.new(@execution_context).call( others: true, ignored: true, exclude_standard: true ).stdout.split("\n").map { |f| Private.unescape_quoted_path(f) } end |
#mv(source, destination, options = {}) ⇒ String
Move or rename a file, directory, or symlink in the working tree
Updates the index after successful completion, but the change must still be committed.
319 320 321 322 |
# File 'lib/git/repository/staging.rb', line 319 def mv(source, destination, = {}) SharedPrivate.assert_valid_opts!(MV_ALLOWED_OPTS, **) Git::Commands::Mv.new(@execution_context).call(*Array(source), destination, verbose: true, **).stdout end |
#read_tree(treeish, opts = {}) ⇒ String
Read tree information into the index
Reads the named tree object into the index. This is a low-level plumbing operation used to stage the contents of a tree without updating the working tree. Typically called before Branching#checkout_index or as part of custom merge flows.
201 202 203 204 |
# File 'lib/git/repository/staging.rb', line 201 def read_tree(treeish, opts = {}) SharedPrivate.assert_valid_opts!(READ_TREE_ALLOWED_OPTS, **opts) Git::Commands::ReadTree.new(@execution_context).call(treeish, **opts).stdout end |
#reset(commitish = nil, opts = {}) ⇒ String
Reset the current HEAD to a specified state
90 91 92 93 |
# File 'lib/git/repository/staging.rb', line 90 def reset(commitish = nil, opts = {}) SharedPrivate.assert_valid_opts!(RESET_ALLOWED_OPTS, **opts) Git::Commands::Reset.new(@execution_context).call(commitish, **opts).stdout end |
#reset_hard(commitish = nil, opts = {}) ⇒ String
Use #reset with hard: true instead.
@example Hard reset to HEAD repo.reset_hard
@example Hard reset to a specific commit repo.reset_hard('HEAD~1')
Reset the current HEAD to a specified state with --hard
116 117 118 119 120 121 122 |
# File 'lib/git/repository/staging.rb', line 116 def reset_hard(commitish = nil, opts = {}) Git::Deprecation.warn( 'Git::Repository::Staging#reset_hard is deprecated and will be removed in a future version. ' \ 'Use #reset(commitish, hard: true) instead.' ) reset(commitish, **opts, hard: true) end |
#rm(path = '.', opts = {}) ⇒ String Also known as: remove
Remove file(s) from the working tree and the index
268 269 270 271 |
# File 'lib/git/repository/staging.rb', line 268 def rm(path = '.', opts = {}) SharedPrivate.assert_valid_opts!(RM_ALLOWED_OPTS, **opts) Git::Commands::Rm.new(@execution_context).call(*Array(path), **opts).stdout end |