mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#565: Refine git_push
rule
This commit is contained in:
parent
cf006dac2c
commit
5ee5439c1e
@ -8,29 +8,29 @@ def match(command):
|
||||
and 'set-upstream' in command.stderr)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
# 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
|
||||
upstream_option_index = -1
|
||||
command_parts = command.script_parts[:]
|
||||
upstream_option_index = _get_upstream_option_index(command_parts)
|
||||
|
||||
try:
|
||||
upstream_option_index = command_parts.index('--set-upstream')
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
upstream_option_index = command_parts.index('-u')
|
||||
except ValueError:
|
||||
pass
|
||||
if upstream_option_index is not -1:
|
||||
if upstream_option_index is not None:
|
||||
command_parts.pop(upstream_option_index)
|
||||
try:
|
||||
|
||||
# In case of `git push -u` we don't have next argument:
|
||||
if len(command_parts) > upstream_option_index:
|
||||
command_parts.pop(upstream_option_index)
|
||||
except IndexError:
|
||||
# This happens for `git push -u`
|
||||
pass
|
||||
|
||||
push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
|
||||
return replace_argument(" ".join(command_parts), 'push', push_upstream)
|
||||
|
Loading…
x
Reference in New Issue
Block a user