mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00: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
|
||||
def output():
|
||||
return '''fatal: The current branch master has no upstream branch.
|
||||
def output(branch_name):
|
||||
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
|
||||
|
||||
git push --set-upstream origin master
|
||||
git push --set-upstream origin {}
|
||||
|
||||
'''
|
||||
'''.format(branch_name, branch_name)
|
||||
|
||||
|
||||
def test_match(output):
|
||||
assert match(Command('git push', output))
|
||||
assert match(Command('git push master', output))
|
||||
assert not match(Command('git push master', ''))
|
||||
assert not match(Command('ls', output))
|
||||
@pytest.mark.parametrize('script, branch_name', [
|
||||
('git push', 'master'),
|
||||
('git push origin', 'master')])
|
||||
def test_match(output, script, branch_name):
|
||||
assert match(Command(script, output))
|
||||
|
||||
|
||||
def test_get_new_command(output):
|
||||
assert get_new_command(Command('git push', output))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push master', output))\
|
||||
== "git push --set-upstream origin master"
|
||||
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))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push origin', output))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push --set-upstream origin', output))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push --quiet', output))\
|
||||
== "git push --set-upstream origin master --quiet"
|
||||
assert get_new_command(Command('git push --quiet origin', output))\
|
||||
== "git push --set-upstream origin master --quiet"
|
||||
assert get_new_command(Command('git -c test=test push --quiet origin', output))\
|
||||
== "git -c test=test push --set-upstream origin master --quiet"
|
||||
@pytest.mark.parametrize('script, branch_name', [
|
||||
('git push master', None),
|
||||
('ls', 'master')])
|
||||
def test_not_match(output, script, branch_name):
|
||||
assert not match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, branch_name, new_command', [
|
||||
('git push', 'master',
|
||||
'git push --set-upstream origin master'),
|
||||
('git push master', 'master',
|
||||
'git push --set-upstream origin master'),
|
||||
('git push -u', 'master',
|
||||
'git push --set-upstream origin master'),
|
||||
('git push -u origin', 'master',
|
||||
'git push --set-upstream origin master'),
|
||||
('git push origin', 'master',
|
||||
'git push --set-upstream origin master'),
|
||||
('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
|
||||
def match(command):
|
||||
return ('push' in command.script
|
||||
return ('push' in command.script_parts
|
||||
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] != '-':
|
||||
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',
|
||||
'push {}'.format(arguments))
|
||||
|
Loading…
x
Reference in New Issue
Block a user