From 84c16fb69a4c0abcb9fe1c90787076800320a950 Mon Sep 17 00:00:00 2001 From: ik1ne <3996272+ik1ne@users.noreply.github.com> Date: Tue, 3 Sep 2019 02:16:40 +0900 Subject: [PATCH] Change: rules_git_checkout handling branch names with slashes & Remote HEAD. (#944) * Add: Test for branch names with slashes & Remote HEAD. * - Add: Handling for removing remote HEAD. - Change: Improved handling for branches with slash in their names. --- tests/rules/test_git_checkout.py | 5 +++++ thefuck/rules/git_checkout.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_git_checkout.py b/tests/rules/test_git_checkout.py index 20fff03c..c54be16c 100644 --- a/tests/rules/test_git_checkout.py +++ b/tests/rules/test_git_checkout.py @@ -39,6 +39,11 @@ def test_not_match(command): (b'', []), (b'* master', ['master']), (b' remotes/origin/master', ['master']), + (b' remotes/origin/test/1', ['test/1']), + (b' remotes/origin/test/1/2/3', ['test/1/2/3']), + (b' test/1', ['test/1']), + (b' test/1/2/3', ['test/1/2/3']), + (b' remotes/origin/HEAD -> origin/master', []), (b' just-another-branch', ['just-another-branch']), (b'* master\n just-another-branch', ['master', 'just-another-branch']), (b'* master\n remotes/origin/master\n just-another-branch', diff --git a/thefuck/rules/git_checkout.py b/thefuck/rules/git_checkout.py index b500652f..6345cbc3 100644 --- a/thefuck/rules/git_checkout.py +++ b/thefuck/rules/git_checkout.py @@ -18,10 +18,12 @@ def get_branches(): stdout=subprocess.PIPE) for line in proc.stdout.readlines(): line = line.decode('utf-8') + if '->' in line: # Remote HEAD like b' remotes/origin/HEAD -> origin/master' + continue if line.startswith('*'): line = line.split(' ')[1] - if '/' in line: - line = line.split('/')[-1] + if line.strip().startswith('remotes/'): + line = '/'.join(line.split('/')[2:]) yield line.strip()