2015-08-25 14:09:47 +03:00
|
|
|
from functools import wraps
|
|
|
|
import re
|
|
|
|
from shlex import split
|
|
|
|
from ..types import Command
|
2015-08-27 16:42:09 +03:00
|
|
|
from ..utils import quote, for_app
|
2015-08-25 14:09:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
def git_support(fn):
|
|
|
|
"""Resolves git aliases and supports testing for both git and hub."""
|
2015-08-27 16:42:09 +03:00
|
|
|
# supports GitHub's `hub` command
|
|
|
|
# which is recommended to be used with `alias git=hub`
|
|
|
|
# but at this point, shell aliases have already been resolved
|
|
|
|
|
|
|
|
@for_app('git', 'hub')
|
2015-08-25 14:09:47 +03:00
|
|
|
@wraps(fn)
|
|
|
|
def wrapper(command, settings):
|
|
|
|
# perform git aliases expansion
|
|
|
|
if 'trace: alias expansion:' in command.stderr:
|
|
|
|
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
|
|
|
|
command.stderr)
|
|
|
|
alias = search.group(1)
|
|
|
|
|
|
|
|
# by default git quotes everything, for example:
|
|
|
|
# 'commit' '--amend'
|
|
|
|
# which is surprising and does not allow to easily test for
|
|
|
|
# eg. 'git commit'
|
|
|
|
expansion = ' '.join(map(quote, split(search.group(2))))
|
|
|
|
new_script = command.script.replace(alias, expansion)
|
|
|
|
|
|
|
|
command = Command._replace(command, script=new_script)
|
|
|
|
|
|
|
|
return fn(command, settings)
|
|
|
|
|
|
|
|
return wrapper
|