mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-11-04 00:52:04 +00:00 
			
		
		
		
	Merge pull request #530 from scorphus/git-branch-exists-checkout
#N/A: Use git_branch_exists rule with `checkout` too
This commit is contained in:
		@@ -12,22 +12,23 @@ def stderr(branch_name):
 | 
				
			|||||||
def new_command(branch_name):
 | 
					def new_command(branch_name):
 | 
				
			||||||
    return [cmd.format(branch_name) for cmd in [
 | 
					    return [cmd.format(branch_name) for cmd in [
 | 
				
			||||||
        'git branch -d {0} && git branch {0}',
 | 
					        'git branch -d {0} && git branch {0}',
 | 
				
			||||||
        'git branch -D {0} && git branch {0}', 'git checkout {0}']]
 | 
					        'git branch -d {0} && git checkout -b {0}',
 | 
				
			||||||
 | 
					        'git branch -D {0} && git branch {0}',
 | 
				
			||||||
 | 
					        'git branch -D {0} && git checkout -b {0}', 'git checkout {0}']]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize('script, branch_name', [
 | 
					@pytest.mark.parametrize('script, branch_name', [
 | 
				
			||||||
    ('git branch foo', 'foo'),
 | 
					    ('git branch foo', 'foo'), ('git checkout bar', 'bar')])
 | 
				
			||||||
    ('git branch bar', 'bar')])
 | 
					 | 
				
			||||||
def test_match(stderr, script, branch_name):
 | 
					def test_match(stderr, script, branch_name):
 | 
				
			||||||
    assert match(Command(script=script, stderr=stderr))
 | 
					    assert match(Command(script=script, stderr=stderr))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize('script', ['git branch foo', 'git branch bar'])
 | 
					@pytest.mark.parametrize('script', ['git branch foo', 'git checkout bar'])
 | 
				
			||||||
def test_not_match(script):
 | 
					def test_not_match(script):
 | 
				
			||||||
    assert not match(Command(script=script, stderr=''))
 | 
					    assert not match(Command(script=script, stderr=''))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize('script, branch_name, ', [
 | 
					@pytest.mark.parametrize('script, branch_name, ', [
 | 
				
			||||||
    ('git branch foo', 'foo'), ('git branch bar', 'bar')])
 | 
					    ('git branch foo', 'foo'), ('git checkout bar', 'bar')])
 | 
				
			||||||
def test_get_new_command(stderr, new_command, script, branch_name):
 | 
					def test_get_new_command(stderr, new_command, script, branch_name):
 | 
				
			||||||
    assert get_new_command(Command(script=script, stderr=stderr)) == new_command
 | 
					    assert get_new_command(Command(script=script, stderr=stderr)) == new_command
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,8 +6,7 @@ from thefuck.utils import eager
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@git_support
 | 
					@git_support
 | 
				
			||||||
def match(command):
 | 
					def match(command):
 | 
				
			||||||
    return ('branch' in command.script
 | 
					    return ("fatal: A branch named '" in command.stderr
 | 
				
			||||||
            and "fatal: A branch named '" in command.stderr
 | 
					 | 
				
			||||||
            and " already exists." in command.stderr)
 | 
					            and " already exists." in command.stderr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,7 +16,9 @@ def get_new_command(command):
 | 
				
			|||||||
    branch_name = re.findall(
 | 
					    branch_name = re.findall(
 | 
				
			||||||
        r"fatal: A branch named '([^']*)' already exists.", command.stderr)[0]
 | 
					        r"fatal: A branch named '([^']*)' already exists.", command.stderr)[0]
 | 
				
			||||||
    new_command_templates = [['git branch -d {0}', 'git branch {0}'],
 | 
					    new_command_templates = [['git branch -d {0}', 'git branch {0}'],
 | 
				
			||||||
 | 
					                             ['git branch -d {0}', 'git checkout -b {0}'],
 | 
				
			||||||
                             ['git branch -D {0}', 'git branch {0}'],
 | 
					                             ['git branch -D {0}', 'git branch {0}'],
 | 
				
			||||||
 | 
					                             ['git branch -D {0}', 'git checkout -b {0}'],
 | 
				
			||||||
                             ['git checkout {0}']]
 | 
					                             ['git checkout {0}']]
 | 
				
			||||||
    for new_command_template in new_command_templates:
 | 
					    for new_command_template in new_command_templates:
 | 
				
			||||||
        yield shell.and_(*new_command_template).format(branch_name)
 | 
					        yield shell.and_(*new_command_template).format(branch_name)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user