639
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 merge master to branch
|
|
6 """
|
|
7 # TODO: combine with k0s.org/hg/gut
|
|
8
|
|
9 import argparse
|
|
10 import os
|
|
11 import subprocess
|
|
12 import sys
|
|
13 import tempfile
|
|
14 from which import which
|
|
15
|
|
16 class Git(object):
|
|
17 def branch(self):
|
|
18 """returns branch you are on"""
|
|
19 return self.branches()[0]
|
|
20 def branches(self):
|
|
21 """return all branches, active first"""
|
|
22 output = subprocess.check_output(['git', 'branch']).strip()
|
|
23 lines = sorted(output.splitlines(), key=lambda line: line.startswith('*'), reverse=True)
|
|
24 return [line.strip('*').strip() for line in lines]
|
|
25
|
|
26 def diff(self):
|
|
27 """returns diff between active branch and master"""
|
|
28 branch = self.branch()
|
|
29 if branch == 'master':
|
|
30 raise AssertionError("Cannot be on the master branch")
|
|
31 merge_base = subprocess.check_output(['git', 'merge-base', 'HEAD', 'master']).strip()
|
|
32 return subprocess.check_output(['git', 'diff', merge_base])
|
|
33
|
|
34 def merge(self):
|
|
35 pass
|
|
36
|
|
37 def main(args=sys.argv[1:]):
|
|
38
|
|
39 parser = argparse.ArgumentParser(description=__doc__)
|
|
40 options = parser.parse_args(args)
|
|
41
|
|
42 # find branch
|
|
43 git = Git()
|
|
44 print (git.diff())
|
|
45
|
|
46
|
|
47 if __name__ == '__main__':
|
|
48 main()
|