#229 Use closest git command

This commit is contained in:
nvbn
2015-07-08 21:33:30 +03:00
parent c0eae8b85c
commit 27b5b9de6a
2 changed files with 29 additions and 5 deletions
+13 -2
View File
@@ -1,4 +1,6 @@
from difflib import get_close_matches
import re
from thefuck.utils import get_closest
def match(command, settings):
@@ -7,10 +9,19 @@ def match(command, settings):
and 'Did you mean' in command.stderr)
def _get_all_git_matched_commands(stderr):
should_yield = False
for line in stderr.split('\n'):
if 'Did you mean' in line:
should_yield = True
elif should_yield and line:
yield line.strip()
def get_new_command(command, settings):
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
command.stderr)[0]
new_cmd = re.findall(r'Did you mean[^\n]*\n\s*([^\n]*)',
command.stderr)[0]
new_cmd = get_closest(broken_cmd,
_get_all_git_matched_commands(command.stderr))
return command.script.replace(broken_cmd, new_cmd, 1)