diff --git a/README.md b/README.md index 199f37b8a..d3a586812 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; * `git_push_pull` – runs `git pull` when `push` was rejected; * `git_stash` – stashes you local modifications before rebasing or switching branch; +* `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`; * `go_run` – appends `.go` extension when compiling/running Go programs * `grep_recursive` – adds `-r` when you trying to `grep` directory; * `gulp_not_task` – fixes misspelled `gulp` tasks; diff --git a/tests/rules/test_git_two_dashes.py b/tests/rules/test_git_two_dashes.py new file mode 100644 index 000000000..56e6b56b6 --- /dev/null +++ b/tests/rules/test_git_two_dashes.py @@ -0,0 +1,47 @@ +import pytest +from thefuck.rules.git_two_dashes import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def stderr(meant): + return 'error: did you mean `%s` (with two dashes ?)' % meant + + +@pytest.mark.parametrize('command', [ + Command(script='git add -patch', stderr=stderr('--patch')), + Command(script='git checkout -patch', stderr=stderr('--patch')), + Command(script='git commit -amend', stderr=stderr('--amend')), + Command(script='git push -tags', stderr=stderr('--tags')), + Command(script='git rebase -continue', stderr=stderr('--continue'))]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command', [ + Command(script='git add --patch'), + Command(script='git checkout --patch'), + Command(script='git commit --amend'), + Command(script='git push --tags'), + Command(script='git rebase --continue')]) +def test_not_match(command): + assert not match(command) + + +@pytest.mark.parametrize('command, output', [ + (Command(script='git add -patch', stderr=stderr('--patch')), + 'git add --patch'), + (Command(script='git checkout -patch', stderr=stderr('--patch')), + 'git checkout --patch'), + (Command(script='git checkout -patch', stderr=stderr('--patch')), + 'git checkout --patch'), + (Command(script='git init -bare', stderr=stderr('--bare')), + 'git init --bare'), + (Command(script='git commit -amend', stderr=stderr('--amend')), + 'git commit --amend'), + (Command(script='git push -tags', stderr=stderr('--tags')), + 'git push --tags'), + (Command(script='git rebase -continue', stderr=stderr('--continue')), + 'git rebase --continue')]) +def test_get_new_command(command, output): + assert get_new_command(command) == output diff --git a/thefuck/rules/git_two_dashes.py b/thefuck/rules/git_two_dashes.py new file mode 100644 index 000000000..93dcd8703 --- /dev/null +++ b/thefuck/rules/git_two_dashes.py @@ -0,0 +1,14 @@ +from thefuck.utils import replace_argument +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return ('error: did you mean `' in command.stderr + and '` (with two dashes ?)' in command.stderr) + + +@git_support +def get_new_command(command): + to = command.stderr.split('`')[1] + return replace_argument(command.script, to[1:], to)