1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 12:06:04 +00:00

Allow multiple returns from git_checkout (#1022)

* Allow multiple returns from git_checkout

* Remove multiple returns
This commit is contained in:
David Hart 2020-01-13 22:28:20 +00:00 committed by Vladimir Iakovlev
parent b28ece0f34
commit 2ced7a7f33
2 changed files with 16 additions and 10 deletions

View File

@ -56,18 +56,18 @@ def test_get_branches(branches, branch_list, git_branch):
@pytest.mark.parametrize('branches, command, new_command', [
(b'',
Command('git checkout unknown', did_not_match('unknown')),
'git checkout -b unknown'),
['git checkout -b unknown']),
(b'',
Command('git commit unknown', did_not_match('unknown')),
'git branch unknown && git commit unknown'),
['git branch unknown && git commit unknown']),
(b' test-random-branch-123',
Command('git checkout tst-rdm-brnch-123',
did_not_match('tst-rdm-brnch-123')),
'git checkout test-random-branch-123'),
['git checkout test-random-branch-123', 'git checkout -b tst-rdm-brnch-123']),
(b' test-random-branch-123',
Command('git commit tst-rdm-brnch-123',
did_not_match('tst-rdm-brnch-123')),
'git commit test-random-branch-123')])
['git commit test-random-branch-123'])])
def test_get_new_command(branches, command, new_command, git_branch):
git_branch(branches)
assert get_new_command(command) == new_command

View File

@ -34,10 +34,16 @@ def get_new_command(command):
r"did not match any file\(s\) known to git", command.output)[0]
closest_branch = utils.get_closest(missing_file, get_branches(),
fallback_to_first=False)
new_commands = []
if closest_branch:
return replace_argument(command.script, missing_file, closest_branch)
elif command.script_parts[1] == 'checkout':
return replace_argument(command.script, 'checkout', 'checkout -b')
else:
return shell.and_('git branch {}', '{}').format(
missing_file, command.script)
new_commands.append(replace_argument(command.script, missing_file, closest_branch))
if command.script_parts[1] == 'checkout':
new_commands.append(replace_argument(command.script, 'checkout', 'checkout -b'))
if not new_commands:
new_commands.append(shell.and_('git branch {}', '{}').format(
missing_file, command.script))
return new_commands