1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

Allow multiple returns from git_checkout

This commit is contained in:
root 2019-12-11 22:05:05 +00:00
parent d10fc80fa5
commit 794cab8842
2 changed files with 13 additions and 6 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'),
(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,17 @@ 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')
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 new_commands:
return new_commands
else:
# if neither the better options above match, then resort to this
return shell.and_('git branch {}', '{}').format(
missing_file, command.script)