From 83cf97dc26f846d1d9d782e4340692df3be7343f Mon Sep 17 00:00:00 2001 From: David Hart Date: Mon, 1 Jan 2018 23:30:33 +0000 Subject: [PATCH] Suggest git checkout -b (#754) This fixes https://github.com/nvbn/thefuck/issues/632 This uses `script_parts` instead of `script.startswith` to let it work even if there's extra spaces in the command, e.g. git checkout unknown --- tests/rules/test_git_checkout.py | 2 +- thefuck/rules/git_checkout.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_git_checkout.py b/tests/rules/test_git_checkout.py index 355b686..a803f20 100644 --- a/tests/rules/test_git_checkout.py +++ b/tests/rules/test_git_checkout.py @@ -52,7 +52,7 @@ 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 branch unknown && git checkout unknown'), + 'git checkout -b unknown'), (b'', Command('git commit unknown', did_not_match('unknown')), 'git branch unknown && git commit unknown'), diff --git a/thefuck/rules/git_checkout.py b/thefuck/rules/git_checkout.py index 934f0a4..65705f4 100644 --- a/thefuck/rules/git_checkout.py +++ b/thefuck/rules/git_checkout.py @@ -34,6 +34,8 @@ def get_new_command(command): fallback_to_first=False) 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)