mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	Merge pull request #551 from scorphus/git-bisect-usage
#N/A: Add `git_bisect_usage` rule
This commit is contained in:
		| @@ -164,6 +164,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: | |||||||
| * `fix_alt_space` – replaces Alt+Space with Space character; | * `fix_alt_space` – replaces Alt+Space with Space character; | ||||||
| * `fix_file` – opens a file with an error in your `$EDITOR`; | * `fix_file` – opens a file with an error in your `$EDITOR`; | ||||||
| * `git_add` – fixes *"pathspec 'foo' did not match any file(s) known to git."*; | * `git_add` – fixes *"pathspec 'foo' did not match any file(s) known to git."*; | ||||||
|  | * `git_bisect_usage` – fixes `git bisect strt`, `git bisect goood`, `git bisect rset`, etc. when bisecting; | ||||||
| * `git_branch_delete` – changes `git branch -d` to `git branch -D`; | * `git_branch_delete` – changes `git branch -d` to `git branch -D`; | ||||||
| * `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists; | * `git_branch_exists` – offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists; | ||||||
| * `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch; | * `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch; | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								tests/rules/test_git_bisect_usage.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tests/rules/test_git_bisect_usage.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | import pytest | ||||||
|  | from tests.utils import Command | ||||||
|  | from thefuck.rules.git_bisect_usage import match, get_new_command | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.fixture | ||||||
|  | def stderr(): | ||||||
|  |     return ("usage: git bisect [help|start|bad|good|new|old" | ||||||
|  |             "|terms|skip|next|reset|visualize|replay|log|run]") | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('script', [ | ||||||
|  |     'git bisect strt', 'git bisect rset', 'git bisect goood']) | ||||||
|  | def test_match(stderr, script): | ||||||
|  |     assert match(Command(script=script, stderr=stderr)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('script', [ | ||||||
|  |     'git bisect', 'git bisect start', 'git bisect good']) | ||||||
|  | def test_not_match(script): | ||||||
|  |     assert not match(Command(script=script, stderr='')) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('script, new_cmd, ', [ | ||||||
|  |     ('git bisect goood', ['good', 'old', 'log']), | ||||||
|  |     ('git bisect strt', ['start', 'terms', 'reset']), | ||||||
|  |     ('git bisect rset', ['reset', 'next', 'start'])]) | ||||||
|  | def test_get_new_command(stderr, script, new_cmd): | ||||||
|  |     new_cmd = ['git bisect %s' % cmd for cmd in new_cmd] | ||||||
|  |     assert get_new_command(Command(script=script, stderr=stderr)) == new_cmd | ||||||
							
								
								
									
										16
									
								
								thefuck/rules/git_bisect_usage.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								thefuck/rules/git_bisect_usage.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | import re | ||||||
|  | from thefuck.utils import replace_command | ||||||
|  | from thefuck.specific.git import git_support | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @git_support | ||||||
|  | def match(command): | ||||||
|  |     return ('bisect' in command.script_parts and | ||||||
|  |             'usage: git bisect' in command.stderr) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @git_support | ||||||
|  | def get_new_command(command): | ||||||
|  |     broken = re.findall(r'git bisect ([^ $]*).*', command.script)[0] | ||||||
|  |     usage = re.findall(r'usage: git bisect \[([^\]]+)\]', command.stderr)[0] | ||||||
|  |     return replace_command(command, broken, usage.split('|')) | ||||||
		Reference in New Issue
	
	Block a user