mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
git_push: Make option handling more robust (#751)
See https://github.com/nvbn/thefuck/issues/740#issuecomment-354466567
This commit is contained in:
parent
83cf97dc26
commit
57fb6e079a
@ -29,7 +29,13 @@ def test_get_new_command(output):
|
|||||||
== "git push --set-upstream origin master"
|
== "git push --set-upstream origin master"
|
||||||
assert get_new_command(Command('git push -u origin', output))\
|
assert get_new_command(Command('git push -u origin', output))\
|
||||||
== "git push --set-upstream origin master"
|
== "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))\
|
assert get_new_command(Command('git push --set-upstream origin', output))\
|
||||||
== "git push --set-upstream origin master"
|
== "git push --set-upstream origin master"
|
||||||
assert get_new_command(Command('git push --quiet', output))\
|
assert get_new_command(Command('git push --quiet', output))\
|
||||||
== "git push --set-upstream origin master --quiet"
|
== "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"
|
||||||
|
@ -32,10 +32,12 @@ def get_new_command(command):
|
|||||||
# In case of `git push -u` we don't have next argument:
|
# In case of `git push -u` we don't have next argument:
|
||||||
if len(command_parts) > upstream_option_index:
|
if len(command_parts) > upstream_option_index:
|
||||||
command_parts.pop(upstream_option_index)
|
command_parts.pop(upstream_option_index)
|
||||||
# If the only argument is the remote/branch, remove it.
|
else:
|
||||||
# git's suggestion includes it, so it won't be lost, and we would duplicate it otherwise.
|
# the only non-qualified permitted options are the repository and refspec; git's
|
||||||
elif len(command_parts) is 3 and command_parts[2][0] != '-':
|
# suggestion include them, so they won't be lost, but would be duplicated otherwise.
|
||||||
command_parts.pop(2)
|
push_idx = command_parts.index('push') + 1
|
||||||
|
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].strip()
|
||||||
return replace_argument(" ".join(command_parts), 'push',
|
return replace_argument(" ".join(command_parts), 'push',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user