mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-15 07:10:52 +01:00
#N/A: Add new git_branch_delete_checked_out
rule (#985)
This commit is contained in:
parent
0ccb34bde8
commit
80cfd6991d
@ -201,6 +201,7 @@ following rules are enabled by default:
|
|||||||
* `git_add_force` – adds `--force` to `git add <pathspec>...` when paths are .gitignore'd;
|
* `git_add_force` – adds `--force` to `git add <pathspec>...` when paths are .gitignore'd;
|
||||||
* `git_bisect_usage` – fixes `git bisect strt`, `git bisect goood`, `git bisect rset`, etc. when bisecting;
|
* `git_bisect_usage` – fixes `git bisect strt`, `git bisect goood`, `git bisect rset`, etc. when bisecting;
|
||||||
* `git_branch_delete` – changes `git branch -d` to `git branch -D`;
|
* `git_branch_delete` – changes `git branch -d` to `git branch -D`;
|
||||||
|
* `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_checkout` – fixes branch name or creates new branch;
|
* `git_checkout` – fixes branch name or creates new branch;
|
||||||
|
29
tests/rules/test_git_branch_delete_checked_out.py
Normal file
29
tests/rules/test_git_branch_delete_checked_out.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import pytest
|
||||||
|
from thefuck.rules.git_branch_delete_checked_out import match, get_new_command
|
||||||
|
from thefuck.types import Command
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def output():
|
||||||
|
return "error: Cannot delete branch 'foo' checked out at '/bar/foo'"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("script", ["git branch -d foo", "git branch -D foo"])
|
||||||
|
def test_match(script, output):
|
||||||
|
assert match(Command(script, output))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("script", ["git branch -d foo", "git branch -D foo"])
|
||||||
|
def test_not_match(script):
|
||||||
|
assert not match(Command(script, "Deleted branch foo (was a1b2c3d)."))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"script, new_command",
|
||||||
|
[
|
||||||
|
("git branch -d foo", "git checkout master && git branch -D foo"),
|
||||||
|
("git branch -D foo", "git checkout master && git branch -D foo"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_get_new_command(script, new_command, output):
|
||||||
|
assert get_new_command(Command(script, output)) == new_command
|
19
thefuck/rules/git_branch_delete_checked_out.py
Normal file
19
thefuck/rules/git_branch_delete_checked_out.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from thefuck.shells import shell
|
||||||
|
from thefuck.specific.git import git_support
|
||||||
|
from thefuck.utils import replace_argument
|
||||||
|
|
||||||
|
|
||||||
|
@git_support
|
||||||
|
def match(command):
|
||||||
|
return (
|
||||||
|
("branch -d" in command.script or "branch -D" in command.script)
|
||||||
|
and "error: Cannot delete branch '" in command.output
|
||||||
|
and "' checked out at '" in command.output
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@git_support
|
||||||
|
def get_new_command(command):
|
||||||
|
return shell.and_("git checkout master", "{}").format(
|
||||||
|
replace_argument(command.script, "-d", "-D")
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user