-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathourgit.py
More file actions
56 lines (43 loc) · 1.21 KB
/
Copy pathourgit.py
File metadata and controls
56 lines (43 loc) · 1.21 KB
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
56
import os
import subprocess as sp
import logging
for p in ('/usr/bin/git', '/usr/local/bin/git'):
if os.path.exists(p):
git_binary = p
def oneline(cmd):
try:
p = sp.Popen(cmd.split(" "), stdout=sp.PIPE, close_fds=True, executable=git_binary)
p.wait()
return p.stdout.readline()
except OSError:
return "Couldn't find binary (probably)"
def sp_stdout(cmd):
try:
p = sp.Popen(cmd.split(" "), stdout=sp.PIPE, close_fds=True)
yield p.stdout
except OSError:
raise StopIteration
def current_branch():
with sp_stdout('git branch') as branchout:
while True:
i = stdout.readline()
if i.startswith("*"):
return i[1:].strip()
return False
def update_git():
data = oneline("git pull")
logging.info("Updated source to %s" % data)
return data
# TODO sanity check
def checkout_git(branch):
return oneline('git checkout %s' % branch)
def update_git_head():
return oneline('git reset --hard HEAD')
def version():
return oneline('git show --shortstat HEAD')[:16]
def log():
return ""
def clean_git():
pass
def git(cmd):
return oneline("git %s" % cmd)