fix shelve-and-goto
[git-knacks.git] / git-unshelve
blob8f8b22ae1d17e855419617993fb417cb21a38f52
1 #!/usr/bin/env ruby
3 #this will shelve your current changes to a new branch
4 require 'optparse'
6 class Unshelve
7 attr_accessor :options
9 def initialize
10 options = {}
11 branch = OptionParser.new do |opts|
12 opts.on("-v", "--[no-]verbose", "Verbose output (echo individual git commands)") do |v|
13 options[:verbose] = v
14 end
15 end.parse!
16 self.options = {:verbose => false}.merge options
17 end
19 def run
20 if get('git-log --pretty=\'format:%s\' -n1').strip == 'SHELVE SHELVE SHELVE'
21 git('git-reset --soft HEAD^')
22 git('git-reset')
23 end
24 end
27 private
29 def git(cmd)
30 puts cmd if options[:verbose]
31 system cmd
32 end
34 def get(cmd)
35 puts cmd if options[:verbose]
36 `#{cmd}`
37 end
38 end
40 Unshelve.new.run