mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Add git merge rule (#755)
This fixes https://github.com/nvbn/thefuck/issues/629
This commit is contained in:
		
				
					committed by
					
						 Joseph Frazier
						Joseph Frazier
					
				
			
			
				
	
			
			
			
						parent
						
							897572d278
						
					
				
				
					commit
					f700b23f57
				
			| @@ -191,6 +191,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: | |||||||
| * `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`); | * `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`); | ||||||
| * `git_flag_after_filename` – fixes `fatal: bad flag '...' after filename` | * `git_flag_after_filename` – fixes `fatal: bad flag '...' after filename` | ||||||
| * `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command; | * `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command; | ||||||
|  | * `git_merge` – adds remote to branch names; | ||||||
| * `git_not_command` – fixes wrong git commands like `git brnch`; | * `git_not_command` – fixes wrong git commands like `git brnch`; | ||||||
| * `git_pull` – sets upstream before executing previous `git pull`; | * `git_pull` – sets upstream before executing previous `git pull`; | ||||||
| * `git_pull_clone` – clones instead of pulling when the repo does not exist; | * `git_pull_clone` – clones instead of pulling when the repo does not exist; | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								tests/rules/test_git_merge.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								tests/rules/test_git_merge.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | import pytest | ||||||
|  | from thefuck.rules.git_merge import match, get_new_command | ||||||
|  | from thefuck.types import Command | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.fixture | ||||||
|  | def output(): | ||||||
|  |     return 'merge: local - not something we can merge\n\n' \ | ||||||
|  |         'Did you mean this?\n\tremote/local' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def test_match(output): | ||||||
|  |     assert match(Command('git merge test', output)) | ||||||
|  |     assert not match(Command('git merge master', '')) | ||||||
|  |     assert not match(Command('ls', output)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('command, new_command', [ | ||||||
|  |     (Command('git merge local', output()), | ||||||
|  |      'git merge remote/local'), | ||||||
|  |     (Command('git merge -m "test" local', output()), | ||||||
|  |      'git merge -m "test" remote/local'), | ||||||
|  |     (Command('git merge -m "test local" local', output()), | ||||||
|  |      'git merge -m "test local" remote/local')]) | ||||||
|  | def test_get_new_command(command, new_command): | ||||||
|  |     assert get_new_command(command) == new_command | ||||||
							
								
								
									
										18
									
								
								thefuck/rules/git_merge.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								thefuck/rules/git_merge.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | import re | ||||||
|  | from thefuck.utils import replace_argument | ||||||
|  | from thefuck.specific.git import git_support | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @git_support | ||||||
|  | def match(command): | ||||||
|  |     return ('merge' in command.script | ||||||
|  |             and ' - not something we can merge' in command.output | ||||||
|  |             and 'Did you mean this?' in command.output) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @git_support | ||||||
|  | def get_new_command(command): | ||||||
|  |     unknown_branch = re.findall(r'merge: (.+) - not something we can merge', command.output)[0] | ||||||
|  |     remote_branch = re.findall(r'Did you mean this\?\n\t([^\n]+)', command.output)[0] | ||||||
|  |  | ||||||
|  |     return replace_argument(command.script, unknown_branch, remote_branch) | ||||||
		Reference in New Issue
	
	Block a user