forked from aspiers/git-explode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitutils.py
More file actions
41 lines (32 loc) · 1.06 KB
/
gitutils.py
File metadata and controls
41 lines (32 loc) · 1.06 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import
import subprocess
class GitUtils(object):
@classmethod
def git(cls, *args):
cmd_words = ['git'] + list(args)
print(' '.join(cmd_words))
return cls.quiet_git(*args)
@classmethod
def quiet_git(cls, *args):
cmd_words = ['git'] + list(args)
output = subprocess.check_output(cmd_words, universal_newlines=True)
return output.rstrip()
@classmethod
def get_head(cls):
"""Retrieve the branch or reference to the current HEAD.
"""
try:
return cls.quiet_git('symbolic-ref', '--short', '-q', 'HEAD')
except subprocess.CalledProcessError:
return cls.get_head_sha1()
@classmethod
def get_head_sha1(cls):
return cls.quiet_git('rev-parse', 'HEAD')
@classmethod
def checkout(cls, branch):
cls.git('checkout', '-q', branch)
@classmethod
def checkout_new(cls, branch, at):
cls.git('checkout', '-q', '-b', branch, at)