-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmove.py
executable file
·55 lines (45 loc) · 1.79 KB
/
gmove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# taken from http://www.jperla.com/blog/post/a-clean-python-shell-script
import os
import re
import subprocess
import logging
import optparse
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s')
def main():
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage)
parser.add_option("-t", "--tag",
action="store",
type="string",
dest="tag",
help="the tag to change to")
parser.add_option("-k", "--keep-old-stash", dest="keepoldstash",
action="store_true",
default=False,
help="keeps your old stash intact")
parser.add_option("-j", "--just-stash", dest="juststash",
action="store_true",
default=False,
help="stash, but do not undo anything")
parser.add_option("-c", "--clear-stash", dest="clearstash",
action="store_true",
default=True,
help="clears the complete stash after command")
options, args = parser.parse_args()
if not options.tag:
parser.error('you have to enter a tag to go to, try -t tagname')
output,_ = call_command('git stash')
output,_ = call_command('git checkout '+ options.tag)
if options.clearstash:
output,_ = call_command('git stash clear')
elif options.keepoldstash:
output,_ = call_command('git stash drop')
def call_command(command):
process = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return process.communicate()
if __name__ == "__main__":
main()