Start support for git aliases

This commit is contained in:
mcarton
2015-07-16 20:23:31 +02:00
parent 78769e4fbc
commit b3e09d68df
4 changed files with 32 additions and 3 deletions
+20
View File
@@ -2,6 +2,7 @@ from difflib import get_close_matches
from functools import wraps
import os
import pickle
import re
import six
from .types import Command
@@ -73,6 +74,25 @@ def sudo_support(fn):
return wrapper
def git_support(fn):
"""Resolve git aliases."""
@wraps(fn)
def wrapper(command, settings):
if (command.script.startswith('git') and
'trace: alias expansion:' in command.stderr):
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
command.stderr)
alias = search.group(1)
expansion = search.group(2)
new_script = command.script.replace(alias, expansion)
command = Command._replace(command, script=new_script)
return fn(command, settings)
return wrapper
def memoize(fn):
"""Caches previous calls to the function."""
memo = {}