mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Merge branch 'master' into josephfrazier-git-push-u
# Conflicts: # thefuck/rules/git_push.py
This commit is contained in:
		| @@ -273,7 +273,9 @@ side_effect(old_command: Command, fixed_command: str) -> None | |||||||
| ``` | ``` | ||||||
| and optional `enabled_by_default`, `requires_output` and `priority` variables. | 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`. | *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)). | `settings` is a special object filled with `~/.config/thefuck/settings.py` and values from env ([see more below](#settings)). | ||||||
|   | |||||||
| @@ -8,7 +8,8 @@ def match(command): | |||||||
|  |  | ||||||
|  |  | ||||||
| def get_new_command(command): | def get_new_command(command): | ||||||
|     command.script_parts[1] = 'link' |     command_parts = command.script_parts[:] | ||||||
|     command.script_parts.insert(2, '--overwrite') |     command_parts[1] = 'link' | ||||||
|     command.script_parts.insert(3, '--dry-run') |     command_parts.insert(2, '--overwrite') | ||||||
|     return ' '.join(command.script_parts) |     command_parts.insert(3, '--dry-run') | ||||||
|  |     return ' '.join(command_parts) | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ def match(command): | |||||||
|  |  | ||||||
|  |  | ||||||
| def get_new_command(command): | def get_new_command(command): | ||||||
|     command.script_parts[1] = 'uninstall' |     command_parts = command.script_parts[:] | ||||||
|     command.script_parts.insert(2, '--force') |     command_parts[1] = 'uninstall' | ||||||
|     return ' '.join(command.script_parts) |     command_parts.insert(2, '--force') | ||||||
|  |     return ' '.join(command_parts) | ||||||
|   | |||||||
| @@ -14,21 +14,23 @@ def get_new_command(command): | |||||||
|     # 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 |     upstream_option_index = -1 | ||||||
|  |     command_parts = command.script_parts[:] | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         upstream_option_index = command.script_parts.index('--set-upstream') |         upstream_option_index = command_parts.index('--set-upstream') | ||||||
|     except ValueError: |     except ValueError: | ||||||
|         pass |         pass | ||||||
|     try: |     try: | ||||||
|         upstream_option_index = command.script_parts.index('-u') |         upstream_option_index = command_parts.index('-u') | ||||||
|     except ValueError: |     except ValueError: | ||||||
|         pass |         pass | ||||||
|     if upstream_option_index is not -1: |     if upstream_option_index is not -1: | ||||||
|         command.script_parts.pop(upstream_option_index) |         command_parts.pop(upstream_option_index) | ||||||
|         try: |         try: | ||||||
|             command.script_parts.pop(upstream_option_index) |             command_parts.pop(upstream_option_index) | ||||||
|         except IndexError: |         except IndexError: | ||||||
|             # This happens for `git push -u` |             # This happens for `git push -u` | ||||||
|             pass |             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.script_parts), 'push', push_upstream) |     return replace_argument(" ".join(command_parts), 'push', push_upstream) | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ def match(command): | |||||||
|  |  | ||||||
| @git_support | @git_support | ||||||
| def get_new_command(command): | def get_new_command(command): | ||||||
|     index = command.script_parts.index('rm') + 1 |     command_parts = command.script_parts[:] | ||||||
|     command.script_parts.insert(index, '-r') |     index = command_parts.index('rm') + 1 | ||||||
|     return u' '.join(command.script_parts) |     command_parts.insert(index, '-r') | ||||||
|  |     return u' '.join(command_parts) | ||||||
|   | |||||||
| @@ -6,9 +6,8 @@ from thefuck.specific.sudo import sudo_support | |||||||
|  |  | ||||||
| @sudo_support | @sudo_support | ||||||
| def match(command): | def match(command): | ||||||
|     toks = command.script_parts |     return (command.script_parts | ||||||
|     return (toks |             and command.script_parts[0].endswith('.py') | ||||||
|             and toks[0].endswith('.py') |  | ||||||
|             and ('Permission denied' in command.stderr or |             and ('Permission denied' in command.stderr or | ||||||
|                  'command not found' in command.stderr)) |                  'command not found' in command.stderr)) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,6 +17,6 @@ def match(command): | |||||||
|  |  | ||||||
| @sudo_support | @sudo_support | ||||||
| def get_new_command(command): | def get_new_command(command): | ||||||
|     cmd = command.script_parts |     cmd = command.script_parts[:] | ||||||
|     cmd[-1], cmd[-2] = cmd[-2], cmd[-1] |     cmd[-1], cmd[-2] = cmd[-2], cmd[-1] | ||||||
|     return ' '.join(cmd) |     return ' '.join(cmd) | ||||||
|   | |||||||
| @@ -34,7 +34,8 @@ class Command(object): | |||||||
|             except Exception: |             except Exception: | ||||||
|                 logs.debug(u"Can't split command script {} because:\n {}".format( |                 logs.debug(u"Can't split command script {} because:\n {}".format( | ||||||
|                     self, sys.exc_info())) |                     self, sys.exc_info())) | ||||||
|                 self._script_parts = None |                 self._script_parts = [] | ||||||
|  |  | ||||||
|         return self._script_parts |         return self._script_parts | ||||||
|  |  | ||||||
|     def __eq__(self, other): |     def __eq__(self, other): | ||||||
|   | |||||||
| @@ -159,7 +159,7 @@ def is_app(command, *app_names, **kwargs): | |||||||
|     if kwargs: |     if kwargs: | ||||||
|         raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys())) |         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 command.script_parts[0] in app_names | ||||||
|  |  | ||||||
|     return False |     return False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user