1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-16 07:38:50 +00:00

33 lines
1.1 KiB
Python
Raw Normal View History

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-27 16:52:26 +03:00
@decorator
def git_support(fn, command):
"""Resolves git aliases and supports testing for both git and hub."""
# 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: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-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)
command = command.update(script=new_script)
return fn(command)