From 934eeaf4fcee84f22c4f58bdebc1d99ca5e7a31d Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Fri, 30 Sep 2016 16:11:46 -0400 Subject: [PATCH 1/2] Test that `git push -u origin` still works This was broken by https://github.com/nvbn/thefuck/pull/538 --- tests/rules/test_git_push.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/rules/test_git_push.py b/tests/rules/test_git_push.py index 7531472d..d6654964 100644 --- a/tests/rules/test_git_push.py +++ b/tests/rules/test_git_push.py @@ -23,5 +23,9 @@ 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 origin', stderr=stderr))\ + == "git push --set-upstream origin master" + assert get_new_command(Command('git push --set-upstream origin', stderr=stderr))\ + == "git push --set-upstream origin master" assert get_new_command(Command('git push --quiet', stderr=stderr))\ == "git push --set-upstream origin master --quiet" From aa6b18d0ce64b1e9f902a617eb7b88b1b88877d0 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Fri, 30 Sep 2016 16:13:50 -0400 Subject: [PATCH 2/2] Fix suggestions for `git push -u origin` Resolves https://github.com/nvbn/thefuck/issues/558 --- thefuck/rules/git_push.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/thefuck/rules/git_push.py b/thefuck/rules/git_push.py index 86a2ea5a..0a624eb9 100644 --- a/thefuck/rules/git_push.py +++ b/thefuck/rules/git_push.py @@ -10,5 +10,21 @@ def match(command): @git_support def get_new_command(command): + # If --set-upstream or -u are passed, remove it and its argument. This is + # because the remaining arguments are concatenated onto the command suggested + # by git, which includes --set-upstream and its argument + upstream_option_index = -1 + try: + upstream_option_index = command.script_parts.index('--set-upstream') + except ValueError: + pass + try: + upstream_option_index = command.script_parts.index('-u') + except ValueError: + pass + if upstream_option_index is not -1: + command.script_parts.pop(upstream_option_index) + command.script_parts.pop(upstream_option_index) + push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2] - return replace_argument(command.script, 'push', push_upstream) + return replace_argument(" ".join(command.script_parts), 'push', push_upstream)