From c3b1ba763708b8faaaf55717c436c4cd4c57a7ea Mon Sep 17 00:00:00 2001 From: nvbn Date: Fri, 11 Dec 2015 07:41:13 +0800 Subject: [PATCH] #415: Prevent double `sudo` --- tests/rules/test_sudo.py | 1 + thefuck/rules/sudo.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/rules/test_sudo.py b/tests/rules/test_sudo.py index fb6692bc..a065b355 100644 --- a/tests/rules/test_sudo.py +++ b/tests/rules/test_sudo.py @@ -19,6 +19,7 @@ def test_match(stderr, stdout): def test_not_match(): assert not match(Command()) + assert not match(Command(script='sudo ls', stderr='Permission denied')) @pytest.mark.parametrize('before, after', [ diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 121efe74..97114441 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -21,6 +21,9 @@ patterns = ['permission denied', def match(command): + if command.script_parts and command.script_parts[0] == 'sudo': + return False + for pattern in patterns: if pattern.lower() in command.stderr.lower()\ or pattern.lower() in command.stdout.lower():