From 76600cf40a6d6a1834193d5c2c627af2a0dca6be Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Mon, 5 Jun 2017 17:29:42 -0400 Subject: [PATCH 1/2] Update stderr wording of git_not_command This changed in git v2.13.1, see https://github.com/gitster/git/commit/6c486862636be1fe2d5785451c52f5379b0bad24#diff-081cf476dd9ac3b05c183570de47cb23 --- tests/rules/test_git_not_command.py | 6 +++--- thefuck/rules/git_not_command.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index 0c3c06f..ede5aa2 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -7,7 +7,7 @@ from tests.utils import Command def git_not_command(): return """git: 'brnch' is not a git command. See 'git --help'. -Did you mean this? +The most similar command is branch """ @@ -16,7 +16,7 @@ branch def git_not_command_one_of_this(): return """git: 'st' is not a git command. See 'git --help'. -Did you mean one of these? +The most similar commands are status reset stage @@ -29,7 +29,7 @@ stats def git_not_command_closest(): return '''git: 'tags' is not a git command. See 'git --help'. -Did you mean one of these? +The most similar commands are \tstage \ttag ''' diff --git a/thefuck/rules/git_not_command.py b/thefuck/rules/git_not_command.py index cfc8106..3c47013 100644 --- a/thefuck/rules/git_not_command.py +++ b/thefuck/rules/git_not_command.py @@ -6,12 +6,12 @@ from thefuck.specific.git import git_support @git_support def match(command): return (" is not a git command. See 'git --help'." in command.stderr - and 'Did you mean' in command.stderr) + and 'The most similar command' in command.stderr) @git_support def get_new_command(command): broken_cmd = re.findall(r"git: '([^']*)' is not a git command", command.stderr)[0] - matched = get_all_matched_commands(command.stderr) + matched = get_all_matched_commands(command.stderr, 'The most similar command') return replace_command(command, broken_cmd, matched) From b6ed4991037a31a824692b1368cd073d574fc1bf Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Tue, 6 Jun 2017 13:56:13 -0400 Subject: [PATCH 2/2] Make git_not_command stderr detection backward-compatible --- thefuck/rules/git_not_command.py | 5 +++-- thefuck/utils.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/thefuck/rules/git_not_command.py b/thefuck/rules/git_not_command.py index 3c47013..2aecf8d 100644 --- a/thefuck/rules/git_not_command.py +++ b/thefuck/rules/git_not_command.py @@ -6,12 +6,13 @@ from thefuck.specific.git import git_support @git_support def match(command): return (" is not a git command. See 'git --help'." in command.stderr - and 'The most similar command' in command.stderr) + and ('The most similar command' in command.stderr + or 'Did you mean' in command.stderr)) @git_support def get_new_command(command): broken_cmd = re.findall(r"git: '([^']*)' is not a git command", command.stderr)[0] - matched = get_all_matched_commands(command.stderr, 'The most similar command') + matched = get_all_matched_commands(command.stderr, ['The most similar command', 'Did you mean']) return replace_command(command, broken_cmd, matched) diff --git a/thefuck/utils.py b/thefuck/utils.py index 34698a7..dbfc6c3 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -141,12 +141,17 @@ def eager(fn, *args, **kwargs): @eager def get_all_matched_commands(stderr, separator='Did you mean'): + if not isinstance(separator, list): + separator = [separator] should_yield = False for line in stderr.split('\n'): - if separator in line: - should_yield = True - elif should_yield and line: - yield line.strip() + for sep in separator: + if sep in line: + should_yield = True + break + else: + if should_yield and line: + yield line.strip() def replace_command(command, broken, matched):