-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #387 from scorphus/git-two-dashes
Add `git_two_dashes` rule
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |