Module: Git::Repository::Stashing Private
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/stashing.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 stash operations
Each method maps onto a git stash subcommand. Methods that identify or
create a stash entry (#stash_infos, #stash_push, #stash_store) return
StashInfo values; methods that only change or display the stash
return git's stdout. Every method that takes a stash (#stash_apply,
#stash_pop, #stash_drop, #stash_show, #stash_branch) accepts a
StashInfo, a stash@{N} name, an Integer index (0 is the most
recent entry), or nil for the most recent entry. Methods that take
options accept them as a trailing positional Hash, so
repo.stash_apply(index: true) and repo.stash_apply(nil, opts) with a
stored opts Hash both work.
#stashes_all, #stash_save, and #stash_list are the legacy surface. They are deprecated and will be removed in v6.0.0.
Included by Git::Repository.
Instance Method Summary collapse
-
#stash_apply(stash = nil, opts = {}) ⇒ String
private
Apply a stash entry to the working tree, keeping it in the stash list.
-
#stash_branch(branch_name, stash = nil) ⇒ String
private
Create and check out a branch from the commit a stash entry was based on.
-
#stash_clear ⇒ String
private
Remove all stash entries.
-
#stash_create(message = nil) ⇒ String?
private
Create a stash commit without adding it to the stash list.
-
#stash_drop(stash = nil, opts = {}) ⇒ String
private
Remove a single stash entry from the stash list.
-
#stash_infos ⇒ Array<Git::StashInfo>
private
Returns every stash entry as a StashInfo, newest first.
-
#stash_list ⇒ String
deprecated
private
Deprecated.
Use #stash_infos instead and format the entries yourself:
repo.stash_infos.map { |s| "#{s.name}: #{s.message}" }.join("\n"). This method will be removed in v6.0.0, and a later release will reuse the name for a method returningArray<Git::StashInfo>. -
#stash_pop(stash = nil, opts = {}) ⇒ String
private
Apply a stash entry to the working tree and remove it from the stash list.
-
#stash_push(*pathspec, options = {}) ⇒ Git::StashInfo?
private
Save the working tree and index state to a new stash entry.
-
#stash_save(message) ⇒ Boolean
deprecated
private
Deprecated.
Use #stash_push with the
:messageoption instead. It returns the new StashInfo, ornilwhen there were no local changes to save. This method will be removed in v6.0.0. -
#stash_show(stash = nil, opts = {}) ⇒ String
private
Show the changes recorded in a stash entry as a diff.
-
#stash_store(commit, opts = {}) ⇒ Git::StashInfo
private
Add a stash commit created by #stash_create to the stash list.
-
#stashes_all ⇒ Array<Array(Integer, String)>
deprecated
private
Deprecated.
Use #stash_infos instead. It returns StashInfo entries newest first with git's own
stash@{N}indices and the full message. This method will be removed in v6.0.0.
Instance Method Details
#stash_apply(stash = nil, opts = {}) ⇒ 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.
Apply a stash entry to the working tree, keeping it in the stash list
184 185 186 187 188 |
# File 'lib/git/repository/stashing.rb', line 184 def stash_apply(stash = nil, opts = {}) stash, opts = Private.split_stash_and_opts(stash, opts) SharedPrivate.assert_valid_opts!(STASH_APPLY_ALLOWED_OPTS, **opts) Git::Commands::Stash::Apply.new(@execution_context).call(stash, **opts).stdout end |
#stash_branch(branch_name, stash = 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.
Create and check out a branch from the commit a stash entry was based on
Applies the entry on the new branch and, when that succeeds, drops the entry from the stash list.
374 375 376 |
# File 'lib/git/repository/stashing.rb', line 374 def stash_branch(branch_name, stash = nil) Git::Commands::Stash::Branch.new(@execution_context).call(branch_name, stash).stdout end |
#stash_clear ⇒ 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.
Remove all stash entries
Removes all entries from the stash list. Use with caution as this operation cannot be undone.
461 462 463 |
# File 'lib/git/repository/stashing.rb', line 461 def stash_clear Git::Commands::Stash::Clear.new(@execution_context).call.stdout end |
#stash_create(message = 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.
Create a stash commit without adding it to the stash list
The working tree and index are left unchanged. Pass the returned object id to #stash_store to add it to the stash list later.
399 400 401 402 |
# File 'lib/git/repository/stashing.rb', line 399 def stash_create( = nil) oid = Git::Commands::Stash::Create.new(@execution_context).call().stdout.strip oid.empty? ? nil : oid end |
#stash_drop(stash = nil, opts = {}) ⇒ 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.
Remove a single stash entry from the stash list
261 262 263 264 265 |
# File 'lib/git/repository/stashing.rb', line 261 def stash_drop(stash = nil, opts = {}) stash, opts = Private.split_stash_and_opts(stash, opts) SharedPrivate.assert_valid_opts!(STASH_DROP_ALLOWED_OPTS, **opts) Git::Commands::Stash::Drop.new(@execution_context).call(stash, **opts).stdout end |
#stash_infos ⇒ Array<Git::StashInfo>
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 every stash entry as a StashInfo, newest first
The order and indices match git stash list: the first element is
stash@{0}, the most recent entry.
48 49 50 51 |
# File 'lib/git/repository/stashing.rb', line 48 def stash_infos result = Git::Commands::Stash::List.new(@execution_context).call Git::Parsers::Stash.parse_list(result.stdout) end |
#stash_list ⇒ 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.
Use #stash_infos instead and format the entries yourself:
repo.stash_infos.map { |s| "#{s.name}: #{s.message}" }.join("\n").
This method will be removed in v6.0.0, and a later release will reuse
the name for a method returning Array<Git::StashInfo>.
Returns stash entries as a formatted string matching git stash list output
527 528 529 530 531 532 533 |
# File 'lib/git/repository/stashing.rb', line 527 def stash_list Git::Deprecation.warn( 'Git::Repository#stash_list is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#stash_infos instead.' ) stash_infos.map { |info| "#{info.name}: #{info.}" }.join("\n") end |
#stash_pop(stash = nil, opts = {}) ⇒ 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.
Apply a stash entry to the working tree and remove it from the stash list
224 225 226 227 228 |
# File 'lib/git/repository/stashing.rb', line 224 def stash_pop(stash = nil, opts = {}) stash, opts = Private.split_stash_and_opts(stash, opts) SharedPrivate.assert_valid_opts!(STASH_POP_ALLOWED_OPTS, **opts) Git::Commands::Stash::Pop.new(@execution_context).call(stash, **opts).stdout end |
#stash_push(*pathspec, options = {}) ⇒ Git::StashInfo?
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.
Save the working tree and index state to a new stash entry
The stash list is read before and after the push and the entry counts are
compared, so the return value is nil whenever git created no entry. This
holds with quiet: true, which suppresses git's "No local changes to
save" message.
138 139 140 141 142 143 144 145 |
# File 'lib/git/repository/stashing.rb', line 138 def stash_push(*pathspec) pathspec, opts = Private.split_pathspec_and_opts(pathspec) SharedPrivate.assert_valid_opts!(STASH_PUSH_ALLOWED_OPTS, **opts) previous_count = stash_infos.size Git::Commands::Stash::Push.new(@execution_context).call(*pathspec, **opts) entries = stash_infos entries.first if entries.size > previous_count end |
#stash_save(message) ⇒ 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.
Use #stash_push with the :message option instead. It
returns the new StashInfo, or nil when there were no local
changes to save. This method will be removed in v6.0.0.
Save the current working directory and index state to a new stash
555 556 557 558 559 560 561 562 |
# File 'lib/git/repository/stashing.rb', line 555 def stash_save() # rubocop:disable Naming/PredicateMethod Git::Deprecation.warn( 'Git::Repository#stash_save is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#stash_push(message: ...) instead.' ) result = Git::Commands::Stash::Push.new(@execution_context).call(message: ) !result.stdout.include?('No local changes to save') end |
#stash_show(stash = nil, opts = {}) ⇒ 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.
Show the changes recorded in a stash entry as a diff
Without options, git prints a diffstat. The output is returned as git prints it.
345 346 347 348 349 |
# File 'lib/git/repository/stashing.rb', line 345 def stash_show(stash = nil, opts = {}) stash, opts = Private.split_stash_and_opts(stash, opts) SharedPrivate.assert_valid_opts!(STASH_SHOW_ALLOWED_OPTS, **opts) Git::Commands::Stash::Show.new(@execution_context).call(stash, **opts).stdout end |
#stash_store(commit, opts = {}) ⇒ Git::StashInfo
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.
Add a stash commit created by #stash_create to the stash list
The stash list is read after the store to return the new top entry.
440 441 442 443 444 |
# File 'lib/git/repository/stashing.rb', line 440 def stash_store(commit, opts = {}) SharedPrivate.assert_valid_opts!(STASH_STORE_ALLOWED_OPTS, **opts) Git::Commands::Stash::Store.new(@execution_context).call(commit, **opts) stash_infos.first end |
#stashes_all ⇒ Array<Array(Integer, 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.
Use #stash_infos instead. It returns StashInfo entries
newest first with git's own stash@{N} indices and the full message.
This method will be removed in v6.0.0.
The sequential index returned here is not the same as git's
stash@{N} reference used by #stash_apply. In git, stash@{0} is the
most recent stash, while index 0 here is the oldest. To apply a
specific stash from this list, convert the entry's position to a git
reference: 'stash@{%d}' % (total - 1 - index), or pass the string
reference directly to #stash_apply.
Returns all stash entries as an array of index and message pairs
Lists all stash entries in the repository ordered from oldest to newest.
The index is a sequential number starting from 0 for the oldest stash. The
message is the stash description with the leading branch prefix (e.g.
"On main:" or "WIP on main:") stripped.
496 497 498 499 500 501 502 503 504 505 |
# File 'lib/git/repository/stashing.rb', line 496 def stashes_all Git::Deprecation.warn( 'Git::Repository#stashes_all is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#stash_infos instead.' ) stash_infos.reverse.each_with_index.map do |info, i| = info..sub(/^(?:WIP on|On)\s+[^:]+:\s*/, '') [i, ] end end |