1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 20:11:17 +00:00

Merge branch 'master' into josephfrazier-git-push-u

# Conflicts:
#	thefuck/rules/git_push.py
This commit is contained in:
Vladimir Iakovlev 2016-10-08 12:20:23 +02:00
commit cf006dac2c
9 changed files with 29 additions and 22 deletions

View File

@ -273,7 +273,9 @@ side_effect(old_command: Command, fixed_command: str) -> None
```
and optional `enabled_by_default`, `requires_output` and `priority` variables.
`Command` has three attributes: `script`, `stdout` and `stderr`.
`Command` has three attributes: `script`, `stdout`, `stderr` and `script_parts`.
Rule shouldn't change `Command`.
*Rules api changed in 3.0:* For accessing settings in rule you need to import it with `from thefuck.conf import settings`.
`settings` is a special object filled with `~/.config/thefuck/settings.py` and values from env ([see more below](#settings)).

View File

@ -8,7 +8,8 @@ def match(command):
def get_new_command(command):
command.script_parts[1] = 'link'
command.script_parts.insert(2, '--overwrite')
command.script_parts.insert(3, '--dry-run')
return ' '.join(command.script_parts)
command_parts = command.script_parts[:]
command_parts[1] = 'link'
command_parts.insert(2, '--overwrite')
command_parts.insert(3, '--dry-run')
return ' '.join(command_parts)

View File

@ -8,6 +8,7 @@ def match(command):
def get_new_command(command):
command.script_parts[1] = 'uninstall'
command.script_parts.insert(2, '--force')
return ' '.join(command.script_parts)
command_parts = command.script_parts[:]
command_parts[1] = 'uninstall'
command_parts.insert(2, '--force')
return ' '.join(command_parts)

View File

@ -14,21 +14,23 @@ def get_new_command(command):
# 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[:]
try:
upstream_option_index = command.script_parts.index('--set-upstream')
upstream_option_index = command_parts.index('--set-upstream')
except ValueError:
pass
try:
upstream_option_index = command.script_parts.index('-u')
upstream_option_index = command_parts.index('-u')
except ValueError:
pass
if upstream_option_index is not -1:
command.script_parts.pop(upstream_option_index)
command_parts.pop(upstream_option_index)
try:
command.script_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]
return replace_argument(" ".join(command.script_parts), 'push', push_upstream)
return replace_argument(" ".join(command_parts), 'push', push_upstream)

View File

@ -10,6 +10,7 @@ def match(command):
@git_support
def get_new_command(command):
index = command.script_parts.index('rm') + 1
command.script_parts.insert(index, '-r')
return u' '.join(command.script_parts)
command_parts = command.script_parts[:]
index = command_parts.index('rm') + 1
command_parts.insert(index, '-r')
return u' '.join(command_parts)

View File

@ -6,9 +6,8 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command):
toks = command.script_parts
return (toks
and toks[0].endswith('.py')
return (command.script_parts
and command.script_parts[0].endswith('.py')
and ('Permission denied' in command.stderr or
'command not found' in command.stderr))

View File

@ -17,6 +17,6 @@ def match(command):
@sudo_support
def get_new_command(command):
cmd = command.script_parts
cmd = command.script_parts[:]
cmd[-1], cmd[-2] = cmd[-2], cmd[-1]
return ' '.join(cmd)

View File

@ -34,7 +34,8 @@ class Command(object):
except Exception:
logs.debug(u"Can't split command script {} because:\n {}".format(
self, sys.exc_info()))
self._script_parts = None
self._script_parts = []
return self._script_parts
def __eq__(self, other):

View File

@ -159,7 +159,7 @@ def is_app(command, *app_names, **kwargs):
if kwargs:
raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys()))
if command.script_parts is not None and len(command.script_parts) > at_least:
if len(command.script_parts) > at_least:
return command.script_parts[0] in app_names
return False