mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-19 01:00:42 +01:00
#942: Add new git_branch_0v_to_dash_v rule
* fix fuckup `branch 0v` by... ...deleting branch `0v` and running `git branch -v` as the user intended * use quotes consistently * provide new solution implementation based on feedback on PR * rename files to more accurately reflect their more generic contents * update import statement to match new file name * update command name in README.md * separate out matching tests so the pattern is clear for those who add matches in the future
This commit is contained in:
parent
373f445e9b
commit
24576b30b2
@ -231,6 +231,7 @@ following rules are enabled by default:
|
|||||||
* `git_branch_delete_checked_out` – changes `git branch -d` to `git checkout master && git branch -D` when trying to delete a checked out branch;
|
* `git_branch_delete_checked_out` – changes `git branch -d` to `git checkout master && git branch -D` when trying to delete a checked out branch;
|
||||||
* `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists;
|
* `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists;
|
||||||
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
||||||
|
* `git_branch_flag_0_to_flag_dash_v` – undoes `git branch 0v` and runs `git branch -v` in its place;
|
||||||
* `git_checkout` – fixes branch name or creates new branch;
|
* `git_checkout` – fixes branch name or creates new branch;
|
||||||
* `git_clone_git_clone` – replaces `git clone git clone ...` with `git clone ...`
|
* `git_clone_git_clone` – replaces `git clone git clone ...` with `git clone ...`
|
||||||
* `git_commit_amend` – offers `git commit --amend` after previous commit;
|
* `git_commit_amend` – offers `git commit --amend` after previous commit;
|
||||||
|
22
tests/rules/test_git_branch_flag_0_to_flag_dash_v.py
Normal file
22
tests/rules/test_git_branch_flag_0_to_flag_dash_v.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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_git_branch_0v(output):
|
||||||
|
assert match(Command('git branch 0v', output))
|
||||||
|
|
||||||
|
|
||||||
|
def test_matches_no__git_branch_0_anything(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'
|
36
thefuck/rules/git_branch_flag_0_to_flag_dash_v.py
Normal file
36
thefuck/rules/git_branch_flag_0_to_flag_dash_v.py
Normal file
@ -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])
|
Loading…
x
Reference in New Issue
Block a user