Class: Git::Stash Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/git/stash.rb

Overview

Deprecated.

Use Repository#stash_push and StashInfo instead

Represents a single stash entry in a Git repository

This class is deprecated and will be removed in v6.0.0. Use the Repository stash methods and StashInfo instead: Repository#stash_push replaces Git::Stash.new(repo, message) and returns a StashInfo, or nil when there was nothing to stash.

Examples:

Create a stash and inspect the result (deprecated)

stash = Git::Stash.new(repo, 'WIP: feature work')
stash.message  #=> "WIP: feature work"
stash.saved?   #=> true

The replacement

info = repo.stash_push(message: 'WIP: feature work')
info.message   #=> "On main: WIP: feature work"
info.nil?      #=> false

See Also:

  • Repository#stash_push

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, message, existing: false)

Deprecated.

Use Repository#stash_push and Git::StashInfo instead

Initialize a Stash object

When existing is false (the default), immediately calls #save to push the current working-directory state onto the stash stack.

Emits one deprecation warning per object.

Examples:

Create a new stash entry

stash = Git::Stash.new(repo, 'WIP: feature work')
stash.saved?  #=> true

Reference an existing stash without pushing

stash = Git::Stash.new(repo, 'WIP: feature work', existing: true)
stash.saved?  #=> nil

Parameters:

  • base (Git::Repository)

    the git repository

  • message (String)

    the stash message

  • existing (Boolean) (defaults to: false)

    (false) when true, wraps an existing stash entry without pushing any changes



54
55
56
57
58
59
60
61
62
63
# File 'lib/git/stash.rb', line 54

def initialize(base, message, existing: false)
  Git::Deprecation.warn(
    'Git::Stash is deprecated and will be removed in v6.0.0. ' \
    'Use the Git::Repository stash methods (stash_push, stash_infos, stash_apply) ' \
    'and Git::StashInfo instead.'
  )
  @base = base
  @message = message
  save unless existing
end

Instance Attribute Details

#messageString (readonly)

Returns the stash description

Examples:

Read the stash message

stash = Git::Stash.new(repo, 'WIP: feature work', existing: true)
stash.message  #=> "WIP: feature work"

Returns:

  • (String)

    the stash message



102
103
104
# File 'lib/git/stash.rb', line 102

def message
  @message
end

Instance Method Details

#saveBoolean

Saves the current working-directory state to the stash stack

Examples:

Save changes to the stash stack

stash = Git::Stash.new(repo, 'WIP', existing: true)
stash.save  #=> true

Returns:

  • (Boolean)

    true if changes were stashed, false if there were no local changes to save

Raises:



76
77
78
79
# File 'lib/git/stash.rb', line 76

def save
  # stash_save is deprecated too; silence it so one Git::Stash call emits one warning
  @saved = Git::Deprecation.silence { stash_repository.stash_save(@message) }
end

#saved?Boolean?

Returns whether the stash was saved successfully

Examples:

Check if changes were stashed

stash = Git::Stash.new(repo, 'WIP: feature work')
stash.saved?  #=> true

Returns:

  • (Boolean, nil)

    true if changes were stashed, false if there were no local changes, nil if #save has not been called (e.g. existing: true)



90
91
92
# File 'lib/git/stash.rb', line 90

def saved?
  @saved
end

#to_sString

Returns the stash description as a string

Examples:

Convert stash to string

stash = Git::Stash.new(repo, 'WIP: feature work', existing: true)
stash.to_s  #=> "WIP: feature work"

Returns:

  • (String)

    the stash message



112
113
114
# File 'lib/git/stash.rb', line 112

def to_s
  message
end