Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 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,19 @@ | ||
import pytest | ||
from thefuck.rules.git_branch_flag_0_to_flag_dash_v import match, get_new_command | ||
from thefuck.types import Command | ||
|
||
|
||
@pytest.fixture | ||
def output(): | ||
return "" | ||
|
||
|
||
def test_match(output): | ||
assert match(Command('git branch 0v', output)) | ||
assert not match(Command('git branch -v', '')) | ||
assert not match(Command('ls', output)) | ||
|
||
|
||
def test_get_new_command(output): | ||
assert get_new_command(Command('git branch 0v', output))\ | ||
== 'git branch -D 0v && git branch -v' |
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,36 @@ | ||
from thefuck.shells import shell | ||
from thefuck.specific.git import git_support | ||
from thefuck.utils import memoize | ||
|
||
''' | ||
keys are fatfingered entry, values are two-element tuples | ||
where the first element is "the fix" and the second element | ||
is "what you meant to do | ||
''' | ||
# clunky when there's only one key, but as others get added, I _think_ | ||
# this will be cleaner | ||
flags_and_their_fixes = dict() | ||
flags_and_their_fixes["v"] = ('git branch -D 0v', 'git branch -v') | ||
|
||
|
||
@memoize | ||
def _supported_flag_fix(command): | ||
flag = command.script_parts[2:][0] | ||
|
||
if len(flag) == 2 and flag.startswith("0"): | ||
return flags_and_their_fixes[flag[1]] | ||
else: | ||
return None | ||
|
||
|
||
@git_support | ||
def match(command): | ||
return (command.script_parts | ||
and command.script_parts[1] == 'branch' | ||
and _supported_flag_fix(command) is not None) | ||
|
||
|
||
@git_support | ||
def get_new_command(command): | ||
fix_parts = _supported_flag_fix(command) | ||
return shell.and_(fix_parts[0], fix_parts[1]) |