From feb36ede5c518fdc3b6eddf945b2d8b1e2294d15 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Thu, 6 Oct 2016 13:03:34 -0400 Subject: [PATCH] Fix suggestion for `git push -u` This was broken by https://github.com/nvbn/thefuck/pull/559 --- tests/rules/test_git_push.py | 2 ++ thefuck/rules/git_push.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_git_push.py b/tests/rules/test_git_push.py index d6654964..1eb61b23 100644 --- a/tests/rules/test_git_push.py +++ b/tests/rules/test_git_push.py @@ -23,6 +23,8 @@ def test_match(stderr): def test_get_new_command(stderr): assert get_new_command(Command('git push', stderr=stderr))\ == "git push --set-upstream origin master" + assert get_new_command(Command('git push -u', stderr=stderr))\ + == "git push --set-upstream origin master" assert get_new_command(Command('git push -u origin', stderr=stderr))\ == "git push --set-upstream origin master" assert get_new_command(Command('git push --set-upstream origin', stderr=stderr))\ diff --git a/thefuck/rules/git_push.py b/thefuck/rules/git_push.py index 0a624eb9..f64d2ce2 100644 --- a/thefuck/rules/git_push.py +++ b/thefuck/rules/git_push.py @@ -24,7 +24,11 @@ def get_new_command(command): pass if upstream_option_index is not -1: command.script_parts.pop(upstream_option_index) - command.script_parts.pop(upstream_option_index) + try: + command.script_parts.pop(upstream_option_index) + except IndexError: + # This happens for `git push -u` + pass push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2] return replace_argument(" ".join(command.script_parts), 'push', push_upstream)