|
| 1 | +""" |
| 2 | + Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com> |
| 3 | + See full notice in `LICENSE' |
| 4 | +""" |
| 5 | + |
| 6 | +import subprocess |
| 7 | +import shutil |
| 8 | + |
| 9 | + |
| 10 | +def clone(repo: str, path: str): |
| 11 | + result = subprocess.run(['git', 'clone', repo, path, '--recursive'], |
| 12 | + stdout=subprocess.PIPE, |
| 13 | + stderr=subprocess.STDOUT).stdout.decode('utf-8') |
| 14 | + return result |
| 15 | + |
| 16 | + |
| 17 | +def status(path: str): |
| 18 | + result = subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'status'], |
| 19 | + stdout=subprocess.PIPE, |
| 20 | + stderr=subprocess.STDOUT).stdout.decode('utf-8') |
| 21 | + # @todo: Parse git's output and return like 0/1 |
| 22 | + return result |
| 23 | + |
| 24 | + |
| 25 | +def reset(path: str): |
| 26 | + result = subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'fetch', 'origin'], |
| 27 | + stdout=subprocess.PIPE, |
| 28 | + stderr=subprocess.STDOUT).stdout.decode('utf-8') |
| 29 | + result += subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'reset', '--hard', 'origin/master'], |
| 30 | + stdout=subprocess.PIPE, |
| 31 | + stderr=subprocess.STDOUT).stdout.decode('utf-8') |
| 32 | + result += subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'clean', '-f'], |
| 33 | + stdout=subprocess.PIPE, |
| 34 | + stderr=subprocess.STDOUT).stdout.decode('utf-8') |
| 35 | + return result |
| 36 | + |
| 37 | + |
| 38 | +def delete(path: str): |
| 39 | + shutil.rmtree(path) |
| 40 | + return |
| 41 | + |
| 42 | + |
| 43 | +def remove(path: str): |
| 44 | + delete(path) |
0 commit comments