-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.py
31 lines (22 loc) · 1.28 KB
/
git.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
from subprocess import run, PIPE, DEVNULL
# Returns a tuple (value, BOOL) whereas BOOL==True means that the config was fetched from the local .git/config
def config_get(section, key):
value = run(['git', 'config', '--get', '%s.%s' % (section, key)],
stdout=PIPE, stderr=None, encoding='utf_8', universal_newlines=True).stdout[:-1]
local_result = run(['git', 'config', '--local', '--get', '%s.%s' % (section, key)], stdout=DEVNULL, stderr=None)
return value, local_result.returncode == 0
def config_set(section, key, value, local=True):
if local:
result = run(['git', 'config', '--local', '%s.%s' % (section, key), value], stdout=None, stderr=None)
else:
result = run(['git', 'config', '--global', '%s.%s' % (section, key), value], stdout=None, stderr=None)
return result.returncode == 0
def config_unset(section, key, local=True):
if local:
result = run(['git', 'config', '--local', '--unset', '%s.%s' % (section, key)], stdout=None, stderr=None)
else:
result = run(['git', 'config', '--global', '--unset', '%s.%s' % (section, key)], stdout=None, stderr=None)
return result.returncode == 0
def clone(url, args):
print(['git', 'clone'] + args + ['--', url])
return run(['git', 'clone'] + args + ['--', url])