# Path: thefuck/specific/git.py
# @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
#     if not is_app(command, 'git', 'hub'):
#         return False
# 
#     # perform git aliases expansion
#     if command.output and 'trace: alias expansion:' in command.output:
#         search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
#                            command.output)
#         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(shell.quote(part)
#                              for part in shell.split_command(search.group(2)))
#         new_script = re.sub(r"\b{}\b".format(alias), expansion, command.script)
# 
#         command = command.update(script=new_script)
# 
#     return fn(command)
# 
# Path: thefuck/types.py
# class Command(object):
#     """Command that should be fixed."""
# 
#     def __init__(self, script, output):
#         """Initializes command with given values.
# 
#         :type script: basestring
#         :type output: basestring
# 
#         """
#         self.script = script
#         self.output = output
# 
#     @property
#     def stdout(self):
#         logs.warn('`stdout` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def stderr(self):
#         logs.warn('`stderr` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def script_parts(self):
#         if not hasattr(self, '_script_parts'):
#             try:
#                 self._script_parts = shell.split_command(self.script)
#             except Exception:
#                 logs.debug(u"Can't split command script {} because:\n {}".format(
#                     self, sys.exc_info()))
#                 self._script_parts = []
# 
#         return self._script_parts
# 
#     def __eq__(self, other):
#         if isinstance(other, Command):
#             return (self.script, self.output) == (other.script, other.output)
#         else:
#             return False
# 
#     def __repr__(self):
#         return u'Command(script={}, output={})'.format(
#             self.script, self.output)
# 
#     def update(self, **kwargs):
#         """Returns new command with replaced fields.
# 
#         :rtype: Command
# 
#         """
#         kwargs.setdefault('script', self.script)
#         kwargs.setdefault('output', self.output)
#         return Command(**kwargs)
# 
#     @classmethod
#     def from_raw_script(cls, raw_script):
#         """Creates instance of `Command` from a list of script parts.
# 
#         :type raw_script: [basestring]
#         :rtype: Command
#         :raises: EmptyCommand
# 
#         """
#         script = format_raw_script(raw_script)
#         if not script:
#             raise EmptyCommand
# 
#         expanded = shell.from_shell(script)
#         output = get_output(script, expanded)
#         return cls(expanded, output)


import pytest
from thefuck.specific.git import git_support
from thefuck.types import Command


@pytest.mark.parametrize('called, command, output', [
    ('git co', 'git checkout', "19:22:36.299340 git.c:282   trace: alias expansion: co => 'checkout'"),
    ('git com file', 'git commit --verbose file',
     "19:23:25.470911 git.c:282   trace: alias expansion: com => 'commit' '--verbose'"),
    ('git com -m "Initial commit"', 'git commit -m "Initial commit"',
     "19:22:36.299340 git.c:282   trace: alias expansion: com => 'commit'"),
    ('git br -d some_branch', 'git branch -d some_branch',
     "19:22:36.299340 git.c:282   trace: alias expansion: br => 'branch'")])
def test_git_support(called, command, output):
    @git_support
    def fn(command):
        return command.script

    assert fn(Command(called, output)) == 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)])
@pytest.mark.parametrize('output', ['', None])
def test_git_support_match(command, is_git, output):

# Path: thefuck/specific/git.py
# @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
#     if not is_app(command, 'git', 'hub'):
#         return False
# 
#     # perform git aliases expansion
#     if command.output and 'trace: alias expansion:' in command.output:
#         search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
#                            command.output)
#         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(shell.quote(part)
#                              for part in shell.split_command(search.group(2)))
#         new_script = re.sub(r"\b{}\b".format(alias), expansion, command.script)
# 
#         command = command.update(script=new_script)
# 
#     return fn(command)
# 
# Path: thefuck/types.py
# class Command(object):
#     """Command that should be fixed."""
# 
#     def __init__(self, script, output):
#         """Initializes command with given values.
# 
#         :type script: basestring
#         :type output: basestring
# 
#         """
#         self.script = script
#         self.output = output
# 
#     @property
#     def stdout(self):
#         logs.warn('`stdout` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def stderr(self):
#         logs.warn('`stderr` is deprecated, please use `output` instead')
#         return self.output
# 
#     @property
#     def script_parts(self):
#         if not hasattr(self, '_script_parts'):
#             try:
#                 self._script_parts = shell.split_command(self.script)
#             except Exception:
#                 logs.debug(u"Can't split command script {} because:\n {}".format(
#                     self, sys.exc_info()))
#                 self._script_parts = []
# 
#         return self._script_parts
# 
#     def __eq__(self, other):
#         if isinstance(other, Command):
#             return (self.script, self.output) == (other.script, other.output)
#         else:
#             return False
# 
#     def __repr__(self):
#         return u'Command(script={}, output={})'.format(
#             self.script, self.output)
# 
#     def update(self, **kwargs):
#         """Returns new command with replaced fields.
# 
#         :rtype: Command
# 
#         """
#         kwargs.setdefault('script', self.script)
#         kwargs.setdefault('output', self.output)
#         return Command(**kwargs)
# 
#     @classmethod
#     def from_raw_script(cls, raw_script):
#         """Creates instance of `Command` from a list of script parts.
# 
#         :type raw_script: [basestring]
#         :rtype: Command
#         :raises: EmptyCommand
# 
#         """
#         script = format_raw_script(raw_script)
#         if not script:
#             raise EmptyCommand
# 
#         expanded = shell.from_shell(script)
#         output = get_output(script, expanded)
#         return cls(expanded, output)


# Path: tests/specific/test_git.py
import pytest
from thefuck.specific.git import git_support
from thefuck.types import Command



@pytest.mark.parametrize('called, command, output', [
    ('git co', 'git checkout', "19:22:36.299340 git.c:282   trace: alias expansion: co => 'checkout'"),
    ('git com file', 'git commit --verbose file',
     "19:23:25.470911 git.c:282   trace: alias expansion: com => 'commit' '--verbose'"),
    ('git com -m "Initial commit"', 'git commit -m "Initial commit"',
     "19:22:36.299340 git.c:282   trace: alias expansion: com => 'commit'"),
    ('git br -d some_branch', 'git branch -d some_branch',
     "19:22:36.299340 git.c:282   trace: alias expansion: br => 'branch'")])
def test_git_support(called, command, output):
    @git_support
    def fn(command):
        return command.script

    assert fn(Command(called, output)) == 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)])
@pytest.mark.parametrize('output', ['', None])
def test_git_support_match(command, is_git, output):

    @git_support