def __init__(self): ''' >>> 1*2 2 ''' self.git_bin = system("which git").strip() self.git_dir = system("git rev-parse --show-toplevel").strip('\n\r ') self.git_rev = system("git rev-parse HEAD").strip('\n\r ')
def get_remote(self): branch = system("git symbolic-ref -q HEAD").strip('\n\r ') remote = "" if branch: branch = branch.replace("refs/heads/", "", 1) remote = system("git config --get branch." + branch + ".remote").strip('\n\r ') if remote: return remote return None
def install_hooks(self, directory): git_dir = system("git rev-parse --show-toplevel", directory).strip('\n\r ') + "/" git_dir += system("git rev-parse --git-dir", directory).strip('\n\r ') hooks = { "post-commit": ["#!/bin/sh\n", "git geo note\n"], "post-merge": ["#!/bin/sh\n", "git geo note\n"], "post-rewrite": ["#!/bin/sh\n", "git geo postrewrite $@\n"] } for hook, code in hooks.iteritems(): self.install_hook(git_dir, hook, code)
def install_hooks(self, directory): git_dir = os.path.join( system("git rev-parse --show-toplevel", directory).strip('\n\r '), system("git rev-parse --git-dir", directory).strip('\n\r ') ) hooks = { "post-commit": ["#!/bin/sh\n", "git geo note\n"], "post-merge": ["#!/bin/sh\n", "git geo note\n"], "post-rewrite": ["#!/bin/sh\n", "git geo postrewrite $@\n"] } for hook, code in hooks.iteritems(): self.install_hook(git_dir, hook, code)
def add_note(self, rev, note): note_file = tempfile.NamedTemporaryFile() note_file.write(note) note_file.flush() command = "%(git_bin)s notes --ref=geocommit add -F %(note_filename)s %(git_rev)s" % { 'git_bin': self.git_bin, 'git_rev': rev, 'note_filename': note_file.name, } system(command, self.git_dir) note_file.close()
def fetch_and_merge_notes(self, remote): self.fetch_notes(remote) #local_changes = system("git rev-list --max-count=1 FETCH_HEAD..refs/notes/geocommit").strip('\n\r ') remote_changes = system("git rev-list --max-count=1 refs/notes/geocommit..FETCH_HEAD").strip('\n\r ') if remote_changes: print "Merging geocommit notes" system_exit_code("git update-ref refs/notes/geocommit-remote FETCH_HEAD") system_exit_code("git notes --ref geocommit merge --strategy=theirs geocommit-remote") else: print "Already up-to-date."
def cmd_postrewrite(self, argv): if len(argv) < 1: usage("postrewrite") cause = argv[0] # rebase or amend for line in sys.stdin: parts = line.split(" ", 2) old_sha1 = parts[0] new_sha1 = parts[1] if len(parts) > 2: extrainfo = parts[2] old_note = system("git notes --ref geocommit show " + old_sha1).strip("\n\r ") if old_note: self.add_note(new_sha1, old_note + "\n\n") # silently fails if already exists
def get_location(self): parseme = system(EXECUTABLE) return self.parse_funky_description_dump(parseme)