1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

git_push: Don't add duplicate remote/branch name (#745)

This fixes https://github.com/nvbn/thefuck/issues/740
This commit is contained in:
Joseph Frazier 2017-12-27 07:54:52 -05:00 committed by GitHub
parent f966ecd4f5
commit 4ea02a3153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -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))\

View File

@ -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',