mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-19 17:20:39 +01:00
git_push: Escape single quote in branch names (#760)
Parameterize test output fixture. Check for 'push' in command.script_parts than anywhere in command.script.
This commit is contained in:
parent
a696461cd3
commit
b62bb90a0d
@ -4,38 +4,51 @@ from thefuck.types import Command
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def output():
|
def output(branch_name):
|
||||||
return '''fatal: The current branch master has no upstream branch.
|
if not branch_name:
|
||||||
|
return ''
|
||||||
|
return '''fatal: The current branch {} has no upstream branch.
|
||||||
To push the current branch and set the remote as upstream, use
|
To push the current branch and set the remote as upstream, use
|
||||||
|
|
||||||
git push --set-upstream origin master
|
git push --set-upstream origin {}
|
||||||
|
|
||||||
'''
|
'''.format(branch_name, branch_name)
|
||||||
|
|
||||||
|
|
||||||
def test_match(output):
|
@pytest.mark.parametrize('script, branch_name', [
|
||||||
assert match(Command('git push', output))
|
('git push', 'master'),
|
||||||
assert match(Command('git push master', output))
|
('git push origin', 'master')])
|
||||||
assert not match(Command('git push master', ''))
|
def test_match(output, script, branch_name):
|
||||||
assert not match(Command('ls', output))
|
assert match(Command(script, output))
|
||||||
|
|
||||||
|
|
||||||
def test_get_new_command(output):
|
@pytest.mark.parametrize('script, branch_name', [
|
||||||
assert get_new_command(Command('git push', output))\
|
('git push master', None),
|
||||||
== "git push --set-upstream origin master"
|
('ls', 'master')])
|
||||||
assert get_new_command(Command('git push master', output))\
|
def test_not_match(output, script, branch_name):
|
||||||
== "git push --set-upstream origin master"
|
assert not match(Command(script, output))
|
||||||
assert get_new_command(Command('git push -u', output))\
|
|
||||||
== "git push --set-upstream origin master"
|
|
||||||
assert get_new_command(Command('git push -u origin', output))\
|
@pytest.mark.parametrize('script, branch_name, new_command', [
|
||||||
== "git push --set-upstream origin master"
|
('git push', 'master',
|
||||||
assert get_new_command(Command('git push origin', output))\
|
'git push --set-upstream origin master'),
|
||||||
== "git push --set-upstream origin master"
|
('git push master', 'master',
|
||||||
assert get_new_command(Command('git push --set-upstream origin', output))\
|
'git push --set-upstream origin master'),
|
||||||
== "git push --set-upstream origin master"
|
('git push -u', 'master',
|
||||||
assert get_new_command(Command('git push --quiet', output))\
|
'git push --set-upstream origin master'),
|
||||||
== "git push --set-upstream origin master --quiet"
|
('git push -u origin', 'master',
|
||||||
assert get_new_command(Command('git push --quiet origin', output))\
|
'git push --set-upstream origin master'),
|
||||||
== "git push --set-upstream origin master --quiet"
|
('git push origin', 'master',
|
||||||
assert get_new_command(Command('git -c test=test push --quiet origin', output))\
|
'git push --set-upstream origin master'),
|
||||||
== "git -c test=test push --set-upstream origin master --quiet"
|
('git push --set-upstream origin', 'master',
|
||||||
|
'git push --set-upstream origin master'),
|
||||||
|
('git push --quiet', 'master',
|
||||||
|
'git push --set-upstream origin master --quiet'),
|
||||||
|
('git push --quiet origin', 'master',
|
||||||
|
'git push --set-upstream origin master --quiet'),
|
||||||
|
('git -c test=test push --quiet origin', 'master',
|
||||||
|
'git -c test=test push --set-upstream origin master --quiet'),
|
||||||
|
('git push', "test's",
|
||||||
|
"git push --set-upstream origin test\\'s")])
|
||||||
|
def test_get_new_command(output, script, branch_name, new_command):
|
||||||
|
assert get_new_command(Command(script, output)) == new_command
|
||||||
|
@ -5,7 +5,7 @@ from thefuck.specific.git import git_support
|
|||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def match(command):
|
def match(command):
|
||||||
return ('push' in command.script
|
return ('push' in command.script_parts
|
||||||
and 'set-upstream' in command.output)
|
and 'set-upstream' in command.output)
|
||||||
|
|
||||||
|
|
||||||
@ -39,6 +39,6 @@ def get_new_command(command):
|
|||||||
while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
|
while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
|
||||||
command_parts.pop(len(command_parts) - 1)
|
command_parts.pop(len(command_parts) - 1)
|
||||||
|
|
||||||
arguments = re.findall(r'git push (.*)', command.output)[0].strip()
|
arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
|
||||||
return replace_argument(" ".join(command_parts), 'push',
|
return replace_argument(" ".join(command_parts), 'push',
|
||||||
'push {}'.format(arguments))
|
'push {}'.format(arguments))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user