1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-04-17 16:20:49 +01:00
thefuck/thefuck/rules/git_flag_after_filename.py
Joseph Frazier 9cae0bffff git_flag_after_filename: fix flake8 errors
These were found by creating a `.flake8` file containing:

    [flake8]
    ignore = E501,W503
    exclude = venv

then running:

    flake8 $(git diff master... --name-only)

See https://github.com/nvbn/thefuck/pull/563 for running `flake8` in CI
2016-10-31 00:22:24 -04:00

31 lines
808 B
Python

import re
from thefuck.specific.git import git_support
error_pattern = "fatal: bad flag '(.*?)' used after filename"
@git_support
def match(command):
return re.search(error_pattern, command.stderr)
@git_support
def get_new_command(command):
command_parts = command.script_parts[:]
# find the bad flag
bad_flag = re.search(error_pattern, command.stderr).group(1)
bad_flag_index = command_parts.index(bad_flag)
# find the filename
for index in reversed(range(bad_flag_index)):
if command_parts[index][0] != '-':
filename_index = index
break
# swap them
command_parts[bad_flag_index], command_parts[filename_index] = \
command_parts[filename_index], command_parts[bad_flag_index] # noqa: E122
return u' '.join(command_parts)