class BigStash::StashOperator

git stash enhancement operator

Attributes

stashes[R]

Public Class Methods

new(path) click to toggle source
# File lib/big_stash/stash_operator.rb, line 7
def initialize(path)
  @stashes = {}
  @path = path
  IO.popen("cd #{@path}; git stash list") do |io|
    io.each do |line|
      items = line.chop.split(/: /)
      @stashes[items.last] = items.first
    end
  end
end

Public Instance Methods

apply_stash(name) click to toggle source
# File lib/big_stash/stash_operator.rb, line 41
def apply_stash(name)
  if @stashes[name]
    p `cd #{@path}; git stash apply #{@stashes[name]}`
  else
    p %(Nothing to apply, can not find the stash with name '#{name}', continue...)
  end
end
pop_stash(name) click to toggle source
# File lib/big_stash/stash_operator.rb, line 49
def pop_stash(name)
  if @stashes[name]
    p `cd #{@path}; git stash pop #{@stashes[name]}`
  else
    p %(Nothing to pop, can not find the stash with name '#{name}', continue...)
  end
end
stash(name) click to toggle source
# File lib/big_stash/stash_operator.rb, line 18
def stash(name)
  if @stashes[name]
    raise "Already have a stash with name #{name}"
  else
    if can_stash
      p `cd #{@path}; git stash save #{name}`
    else
      p 'Nothing to stash, working tree clean, continue...'
    end
  end
end
stash_for_name(name) click to toggle source
# File lib/big_stash/stash_operator.rb, line 57
def stash_for_name(name)
  @stashes[name]
end

Private Instance Methods

can_stash() click to toggle source
# File lib/big_stash/stash_operator.rb, line 30
def can_stash
  can_stash = true
  clear_flag = 'nothing to commit, working tree clean'
  IO.popen("cd #{@path}; git status") do |io|
    io.each do |line|
      can_stash = false if line.include? clear_flag
    end
  end
  can_stash
end