From 213791d3c2af379ffa37a140735998736b41912e Mon Sep 17 00:00:00 2001 From: nvbn Date: Thu, 10 Sep 2015 14:28:22 +0300 Subject: [PATCH] #369 Fix `git_fix_stash` fails when script is just `git` --- tests/rules/test_git_fix_stash.py | 4 ++++ thefuck/rules/git_fix_stash.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_git_fix_stash.py b/tests/rules/test_git_fix_stash.py index 206d54fc..6e4ac162 100644 --- a/tests/rules/test_git_fix_stash.py +++ b/tests/rules/test_git_fix_stash.py @@ -23,6 +23,10 @@ def test_match(wrong): assert match(Command(wrong, stderr=git_stash_err)) +def test_not_match(): + assert not match(Command("git", stderr=git_stash_err)) + + @pytest.mark.parametrize('wrong,fixed', [ ('git stash opp', 'git stash pop'), ('git stash Some message', 'git stash save Some message'), diff --git a/thefuck/rules/git_fix_stash.py b/thefuck/rules/git_fix_stash.py index 8cf6ae32..944d37c5 100644 --- a/thefuck/rules/git_fix_stash.py +++ b/thefuck/rules/git_fix_stash.py @@ -5,8 +5,12 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (command.script.split()[1] == 'stash' - and 'usage:' in command.stderr) + splited_script = command.script.split() + if len(splited_script) > 1: + return (splited_script[1] == 'stash' + and 'usage:' in command.stderr) + else: + return False # git's output here is too complicated to be parsed (see the test file) stash_commands = (