Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#N/A: Add new
git_branch_delete_checked_out
rule (#985)
- Loading branch information
Showing
3 changed files
with
49 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,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 |
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 @@ | ||
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") | ||
) |