mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	Make the environment a setting
This would allow other rules to set the environment as needed for `@git_support` and `GIT_TRACE`.
This commit is contained in:
		| @@ -77,23 +77,23 @@ class TestGetCommand(object): | |||||||
|         monkeypatch.setattr('thefuck.shells.to_shell', lambda x: x) |         monkeypatch.setattr('thefuck.shells.to_shell', lambda x: x) | ||||||
|  |  | ||||||
|     def test_get_command_calls(self, Popen): |     def test_get_command_calls(self, Popen): | ||||||
|         assert main.get_command(Mock(), |         assert main.get_command(Mock(env={}), | ||||||
|             ['thefuck', 'apt-get', 'search', 'vim']) \ |             ['thefuck', 'apt-get', 'search', 'vim']) \ | ||||||
|                == Command('apt-get search vim', 'stdout', 'stderr') |                == Command('apt-get search vim', 'stdout', 'stderr') | ||||||
|         Popen.assert_called_once_with('apt-get search vim', |         Popen.assert_called_once_with('apt-get search vim', | ||||||
|                                       shell=True, |                                       shell=True, | ||||||
|                                       stdout=PIPE, |                                       stdout=PIPE, | ||||||
|                                       stderr=PIPE, |                                       stderr=PIPE, | ||||||
|                                       env={'LANG': 'C', 'GIT_TRACE': 1}) |                                       env={}) | ||||||
|  |  | ||||||
|     @pytest.mark.parametrize('args, result', [ |     @pytest.mark.parametrize('args, result', [ | ||||||
|         (['thefuck', 'ls', '-la'], 'ls -la'), |         (['thefuck', 'ls', '-la'], 'ls -la'), | ||||||
|         (['thefuck', 'ls'], 'ls')]) |         (['thefuck', 'ls'], 'ls')]) | ||||||
|     def test_get_command_script(self, args, result): |     def test_get_command_script(self, args, result): | ||||||
|         if result: |         if result: | ||||||
|             assert main.get_command(Mock(), args).script == result |             assert main.get_command(Mock(env={}), args).script == result | ||||||
|         else: |         else: | ||||||
|             assert main.get_command(Mock(), args) is None |             assert main.get_command(Mock(env={}), args) is None | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestGetMatchedRule(object): | class TestGetMatchedRule(object): | ||||||
|   | |||||||
| @@ -30,7 +30,8 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, | |||||||
|                     'require_confirmation': False, |                     'require_confirmation': False, | ||||||
|                     'no_colors': False, |                     'no_colors': False, | ||||||
|                     'debug': False, |                     'debug': False, | ||||||
|                     'priority': {}} |                     'priority': {}, | ||||||
|  |                     'env': {'LANG': 'C', 'GIT_TRACE': '1'}} | ||||||
|  |  | ||||||
| ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', | ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', | ||||||
|                'THEFUCK_WAIT_COMMAND': 'wait_command', |                'THEFUCK_WAIT_COMMAND': 'wait_command', | ||||||
|   | |||||||
| @@ -81,8 +81,12 @@ def get_command(settings, args): | |||||||
|  |  | ||||||
|     script = shells.from_shell(script) |     script = shells.from_shell(script) | ||||||
|     logs.debug('Call: {}'.format(script), settings) |     logs.debug('Call: {}'.format(script), settings) | ||||||
|     result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, |  | ||||||
|                    env=dict(os.environ, LANG='C', GIT_TRACE=1)) |     env = dict(os.environ) | ||||||
|  |     env.update(settings.env) | ||||||
|  |     logs.debug('Executing with env: {}'.format(env), settings) | ||||||
|  |  | ||||||
|  |     result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) | ||||||
|     if wait_output(settings, result): |     if wait_output(settings, result): | ||||||
|         return types.Command(script, result.stdout.read().decode('utf-8'), |         return types.Command(script, result.stdout.read().decode('utf-8'), | ||||||
|                              result.stderr.read().decode('utf-8')) |                              result.stderr.read().decode('utf-8')) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user