mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#1184: Improve + fix git_main_master
rule
This commit is contained in:
parent
70a42b54ab
commit
711feb4df5
@ -3,21 +3,45 @@ from thefuck.rules.git_main_master import match, get_new_command
|
|||||||
from thefuck.types import Command
|
from thefuck.types import Command
|
||||||
|
|
||||||
|
|
||||||
output = 'error: pathspec \'%s\' did not match any file(s) known to git'
|
@pytest.fixture
|
||||||
|
def output(branch_name):
|
||||||
|
if not branch_name:
|
||||||
|
return ""
|
||||||
|
output_str = u"error: pathspec '{}' did not match any file(s) known to git"
|
||||||
|
return output_str.format(branch_name)
|
||||||
|
|
||||||
|
|
||||||
def test_match():
|
@pytest.mark.parametrize(
|
||||||
assert match(Command('git checkout main', output % ('main')))
|
"script, branch_name",
|
||||||
assert match(Command('git checkout master', output % ('master')))
|
[
|
||||||
assert not match(Command('git checkout master', ''))
|
("git checkout main", "main"),
|
||||||
assert not match(Command('git checkout main', ''))
|
("git checkout master", "master"),
|
||||||
assert not match(Command('git checkout wibble', output % ('wibble')))
|
("git show main", "main"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_match(script, branch_name, output):
|
||||||
|
assert match(Command(script, output))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize(
|
||||||
(Command('git checkout main', output % ('main')),
|
"script, branch_name",
|
||||||
'git checkout master'),
|
[
|
||||||
(Command('git checkout master', output % ('master')),
|
("git checkout master", ""),
|
||||||
'git checkout main')])
|
("git checkout main", ""),
|
||||||
def test_get_new_command(command, new_command):
|
("git checkout wibble", "wibble"),
|
||||||
assert get_new_command(command) == new_command
|
],
|
||||||
|
)
|
||||||
|
def test_not_match(script, branch_name, output):
|
||||||
|
assert not match(Command(script, output))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"script, branch_name, new_command",
|
||||||
|
[
|
||||||
|
("git checkout main", "main", "git checkout master"),
|
||||||
|
("git checkout master", "master", "git checkout main"),
|
||||||
|
("git checkout wibble", "wibble", "git checkout wibble"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_get_new_command(script, branch_name, new_command, output):
|
||||||
|
assert get_new_command(Command(script, output)) == new_command
|
||||||
|
@ -3,12 +3,14 @@ from thefuck.specific.git import git_support
|
|||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def match(command):
|
def match(command):
|
||||||
return "'master'" in command.output.lower() or "'main'" in command.output.lower()
|
return "'master'" in command.output or "'main'" in command.output
|
||||||
|
|
||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
if "'master'" in command.output.lower():
|
if "'master'" in command.output:
|
||||||
return command.script.replace("master", "main")
|
return command.script.replace("master", "main")
|
||||||
else:
|
|
||||||
return command.script.replace("main", "master")
|
return command.script.replace("main", "master")
|
||||||
|
|
||||||
|
|
||||||
|
priority = 1200
|
||||||
|
Loading…
x
Reference in New Issue
Block a user