mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-17 16:20:49 +01:00
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
31 lines
808 B
Python
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)
|