diff --git a/tests/rules/test_git_push.py b/tests/rules/test_git_push.py index 7a2b512d..2625c0d9 100644 --- a/tests/rules/test_git_push.py +++ b/tests/rules/test_git_push.py @@ -20,5 +20,5 @@ def test_match(stderr): def test_get_new_command(stderr): - assert get_new_command(Command(stderr=stderr), None)\ + assert get_new_command(Command('git push', stderr=stderr), None)\ == "git push --set-upstream origin master" diff --git a/tests/test_utils.py b/tests/test_utils.py index 39ab00fa..208911d5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -36,6 +36,20 @@ def test_git_support(called, command, stderr): assert fn(Command(script=called, stderr=stderr), None) == command +@pytest.mark.parametrize('command, is_git', [ + ('git pull', True), + ('hub pull', True), + ('git push --set-upstream origin foo', True), + ('hub push --set-upstream origin foo', True), + ('ls', False), + ('cat git', False), + ('cat hub', False)]) +def test_git_support_match(command, is_git): + @git_support + def fn(command, settings): return True + assert fn(Command(script=command), None) == is_git + + def test_memoize(): fn = Mock(__name__='fn') memoized = memoize(fn) diff --git a/thefuck/utils.py b/thefuck/utils.py index 19d696af..5be2c2bb 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -75,12 +75,19 @@ def sudo_support(fn): def git_support(fn): - """Resolve git aliases.""" + """Resolves git aliases and supports testing for both git and hub.""" @wraps(fn) def wrapper(command, settings): - if (command.script.startswith('git') and - 'trace: alias expansion:' in command.stderr): + # 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 + is_git_cmd = command.script.startswith(('git', 'hub')) + if not is_git_cmd: + return False + + # perform git aliases expansion + if 'trace: alias expansion:' in command.stderr: search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)", command.stderr) alias = search.group(1) @@ -93,6 +100,7 @@ def git_support(fn): new_script = command.script.replace(alias, expansion) command = Command._replace(command, script=new_script) + return fn(command, settings) return wrapper