mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-19 17:18:42 +00:00
handle single quotes in git_branch_exists
This commit is contained in:
parent
045c8ae76c
commit
f2ed84002c
@ -4,8 +4,8 @@ from thefuck.types import Command
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def output(branch_name):
|
def output(src_branch_name):
|
||||||
return "fatal: A branch named '{}' already exists.".format(branch_name)
|
return "fatal: A branch named '{}' already exists.".format(src_branch_name)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -17,18 +17,25 @@ def new_command(branch_name):
|
|||||||
'git branch -D {0} && git checkout -b {0}', 'git checkout {0}']]
|
'git branch -D {0} && git checkout -b {0}', 'git checkout {0}']]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, branch_name', [
|
@pytest.mark.parametrize('script, src_branch_name, branch_name', [
|
||||||
('git branch foo', 'foo'), ('git checkout bar', 'bar')])
|
('git branch foo', 'foo', 'foo'),
|
||||||
|
('git checkout bar', 'bar', 'bar'),
|
||||||
|
('git checkout -b "let\s-push-this"', '"let\s-push-this"', '"let\s-push-this"')])
|
||||||
def test_match(output, script, branch_name):
|
def test_match(output, script, branch_name):
|
||||||
assert match(Command(script, output))
|
assert match(Command(script, output))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script', ['git branch foo', 'git checkout bar'])
|
@pytest.mark.parametrize('script', [
|
||||||
|
'git branch foo',
|
||||||
|
'git checkout bar',
|
||||||
|
'git checkout -b "let\s-push-this"'])
|
||||||
def test_not_match(script):
|
def test_not_match(script):
|
||||||
assert not match(Command(script, ''))
|
assert not match(Command(script, ''))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, branch_name, ', [
|
@pytest.mark.parametrize('script, src_branch_name, branch_name', [
|
||||||
('git branch foo', 'foo'), ('git checkout bar', 'bar')])
|
('git branch foo', 'foo', 'foo'),
|
||||||
def test_get_new_command(output, new_command, script, branch_name):
|
('git checkout bar', 'bar', 'bar'),
|
||||||
|
('git checkout -b "let\'s-push-this"', "let's-push-this", "let\\'s-push-this")])
|
||||||
|
def test_get_new_command(output, new_command, script, src_branch_name, branch_name):
|
||||||
assert get_new_command(Command(script, output)) == new_command
|
assert get_new_command(Command(script, output)) == new_command
|
||||||
|
@ -7,14 +7,14 @@ from thefuck.utils import eager
|
|||||||
@git_support
|
@git_support
|
||||||
def match(command):
|
def match(command):
|
||||||
return ("fatal: A branch named '" in command.output
|
return ("fatal: A branch named '" in command.output
|
||||||
and " already exists." in command.output)
|
and "' already exists." in command.output)
|
||||||
|
|
||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
@eager
|
@eager
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
branch_name = re.findall(
|
branch_name = re.findall(
|
||||||
r"fatal: A branch named '([^']*)' already exists.", command.output)[0]
|
r"fatal: A branch named '(.+)' already exists.", command.output)[0].replace("'", r"\'")
|
||||||
new_command_templates = [['git branch -d {0}', 'git branch {0}'],
|
new_command_templates = [['git branch -d {0}', 'git branch {0}'],
|
||||||
['git branch -d {0}', 'git checkout -b {0}'],
|
['git branch -d {0}', 'git checkout -b {0}'],
|
||||||
['git branch -D {0}', 'git branch {0}'],
|
['git branch -D {0}', 'git branch {0}'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user