changeset 639:3be3b16aeda0

stub for merging from master
author Jeff Hammel <k0scist@gmail.com>
date Tue, 04 Mar 2014 11:19:19 -0800
parents 6dedad97c4eb
children 3059ee249888
files python/git_merge_master.py
diffstat 1 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/git_merge_master.py	Tue Mar 04 11:19:19 2014 -0800
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+merge master to branch
+"""
+# TODO: combine with k0s.org/hg/gut
+
+import argparse
+import os
+import subprocess
+import sys
+import tempfile
+from which import which
+
+class Git(object):
+    def branch(self):
+        """returns branch you are on"""
+        return self.branches()[0]
+    def branches(self):
+        """return all branches, active first"""
+        output = subprocess.check_output(['git', 'branch']).strip()
+        lines = sorted(output.splitlines(), key=lambda line: line.startswith('*'), reverse=True)
+        return [line.strip('*').strip() for line in lines]
+
+    def diff(self):
+        """returns diff between active branch and master"""
+        branch = self.branch()
+        if branch == 'master':
+            raise AssertionError("Cannot be on the master branch")
+        merge_base = subprocess.check_output(['git', 'merge-base', 'HEAD', 'master']).strip()
+        return subprocess.check_output(['git', 'diff', merge_base])
+
+    def merge(self):
+        pass
+
+def main(args=sys.argv[1:]):
+
+    parser = argparse.ArgumentParser(description=__doc__)
+    options = parser.parse_args(args)
+
+    # find branch
+    git = Git()
+    print (git.diff())
+
+
+if __name__ == '__main__':
+    main()