2017-08-26 13:39:38 +02:00
|
|
|
import re
|
2016-08-19 22:08:30 +01:00
|
|
|
from thefuck.utils import replace_argument
|
2015-08-25 14:09:47 +03:00
|
|
|
from thefuck.specific.git import git_support
|
2015-07-17 11:55:44 +02:00
|
|
|
|
|
|
|
|
2015-08-25 14:09:47 +03:00
|
|
|
@git_support
|
2015-09-07 13:00:29 +03:00
|
|
|
def match(command):
|
2015-07-21 15:35:39 +02:00
|
|
|
return ('push' in command.script
|
2017-08-31 17:58:56 +02:00
|
|
|
and 'set-upstream' in command.output)
|
2015-04-08 18:15:49 +02:00
|
|
|
|
|
|
|
|
2016-10-08 12:24:48 +02:00
|
|
|
def _get_upstream_option_index(command_parts):
|
|
|
|
if '--set-upstream' in command_parts:
|
|
|
|
return command_parts.index('--set-upstream')
|
|
|
|
elif '-u' in command_parts:
|
|
|
|
return command_parts.index('-u')
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2015-08-25 14:09:47 +03:00
|
|
|
@git_support
|
2015-09-07 13:00:29 +03:00
|
|
|
def get_new_command(command):
|
2016-09-30 16:13:50 -04:00
|
|
|
# If --set-upstream or -u are passed, remove it and its argument. This is
|
|
|
|
# because the remaining arguments are concatenated onto the command suggested
|
|
|
|
# by git, which includes --set-upstream and its argument
|
2016-10-08 12:18:33 +02:00
|
|
|
command_parts = command.script_parts[:]
|
2016-10-08 12:24:48 +02:00
|
|
|
upstream_option_index = _get_upstream_option_index(command_parts)
|
2016-10-08 12:18:33 +02:00
|
|
|
|
2016-10-08 12:24:48 +02:00
|
|
|
if upstream_option_index is not None:
|
2016-10-08 12:18:33 +02:00
|
|
|
command_parts.pop(upstream_option_index)
|
2016-10-08 12:24:48 +02:00
|
|
|
|
|
|
|
# In case of `git push -u` we don't have next argument:
|
|
|
|
if len(command_parts) > upstream_option_index:
|
2016-10-08 12:20:23 +02:00
|
|
|
command_parts.pop(upstream_option_index)
|
2018-01-02 00:45:46 +00:00
|
|
|
else:
|
|
|
|
# the only non-qualified permitted options are the repository and refspec; git's
|
|
|
|
# suggestion include them, so they won't be lost, but would be duplicated otherwise.
|
|
|
|
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)
|
2016-09-30 16:13:50 -04:00
|
|
|
|
2018-01-02 23:17:19 +00:00
|
|
|
arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
|
2017-08-26 13:39:38 +02:00
|
|
|
return replace_argument(" ".join(command_parts), 'push',
|
|
|
|
'push {}'.format(arguments))
|