diff --git a/tests/rules/test_git_push.py b/tests/rules/test_git_push.py index debd7039..c654b2aa 100644 --- a/tests/rules/test_git_push.py +++ b/tests/rules/test_git_push.py @@ -23,6 +23,8 @@ def test_match(output): def test_get_new_command(output): assert get_new_command(Command('git push', output))\ == "git push --set-upstream origin master" + assert get_new_command(Command('git push master', output))\ + == "git push --set-upstream origin master" assert get_new_command(Command('git push -u', output))\ == "git push --set-upstream origin master" assert get_new_command(Command('git push -u origin', output))\ diff --git a/thefuck/rules/git_push.py b/thefuck/rules/git_push.py index 7a472407..c5f49a5c 100644 --- a/thefuck/rules/git_push.py +++ b/thefuck/rules/git_push.py @@ -32,6 +32,10 @@ def get_new_command(command): # In case of `git push -u` we don't have next argument: if len(command_parts) > upstream_option_index: command_parts.pop(upstream_option_index) + # If the only argument is the remote/branch, remove it. + # git's suggestion includes it, so it won't be lost, and we would duplicate it otherwise. + elif len(command_parts) is 3 and command_parts[2][0] != '-': + command_parts.pop(2) arguments = re.findall(r'git push (.*)', command.output)[0].strip() return replace_argument(" ".join(command_parts), 'push',