mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +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)
|
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
|
@git_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
# If --set-upstream or -u are passed, remove it and its argument. This is
|
# If --set-upstream or -u are passed, remove it and its argument. This is
|
||||||
# because the remaining arguments are concatenated onto the command suggested
|
# because the remaining arguments are concatenated onto the command suggested
|
||||||
# by git, which includes --set-upstream and its argument
|
# by git, which includes --set-upstream and its argument
|
||||||
upstream_option_index = -1
|
|
||||||
command_parts = command.script_parts[:]
|
command_parts = command.script_parts[:]
|
||||||
|
upstream_option_index = _get_upstream_option_index(command_parts)
|
||||||
|
|
||||||
try:
|
if upstream_option_index is not None:
|
||||||
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:
|
|
||||||
command_parts.pop(upstream_option_index)
|
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)
|
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]
|
push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
|
||||||
return replace_argument(" ".join(command_parts), 'push', push_upstream)
|
return replace_argument(" ".join(command_parts), 'push', push_upstream)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user