2015-08-25 14:09:47 +03:00
|
|
|
import re
|
2015-08-27 16:52:26 +03:00
|
|
|
from decorator import decorator
|
2015-10-28 14:16:01 +01:00
|
|
|
from ..utils import is_app
|
2016-01-29 13:09:40 +03:00
|
|
|
from ..shells import shell
|
2015-08-25 14:09:47 +03:00
|
|
|
|
|
|
|
|
2015-08-27 16:52:26 +03:00
|
|
|
@decorator
|
2015-09-07 13:00:29 +03:00
|
|
|
def git_support(fn, command):
|
2015-08-25 14:09:47 +03:00
|
|
|
"""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
|
2015-08-27 16:52:26 +03:00
|
|
|
if not is_app(command, 'git', 'hub'):
|
|
|
|
return False
|
2015-08-27 16:42:09 +03:00
|
|
|
|
2015-08-27 16:52:26 +03:00
|
|
|
# perform git aliases expansion
|
|
|
|
if 'trace: alias expansion:' in command.stderr:
|
|
|
|
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
|
|
|
|
command.stderr)
|
|
|
|
alias = search.group(1)
|
2015-08-25 14:09:47 +03:00
|
|
|
|
2015-08-27 16:52:26 +03:00
|
|
|
# by default git quotes everything, for example:
|
|
|
|
# 'commit' '--amend'
|
|
|
|
# which is surprising and does not allow to easily test for
|
|
|
|
# eg. 'git commit'
|
2016-01-29 13:09:40 +03:00
|
|
|
expansion = ' '.join(shell.quote(part)
|
|
|
|
for part in shell.split_command(search.group(2)))
|
2015-08-27 16:52:26 +03:00
|
|
|
new_script = command.script.replace(alias, expansion)
|
2015-08-25 14:09:47 +03:00
|
|
|
|
2015-09-08 15:00:57 +03:00
|
|
|
command = command.update(script=new_script)
|
2015-08-25 14:09:47 +03:00
|
|
|
|
2015-09-07 13:00:29 +03:00
|
|
|
return fn(command)
|