Mercurial > hg > config
view python/git_merge_master.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | 3059ee249888 |
children |
line wrap: on
line source
#!/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 checkout(self, branch): subprocess.check_output(['git', 'checkout', branch]) def pull(self, branch='master'): current_branch = self.branch() if current_branch != branch: self.checkout(branch) subprocess.check_output(['git', 'pull', 'origin', branch]) if current_branch != branch: self.checkout(current_branch) 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()