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

#652: Add new git_push_different_branch_names rule

Fix #652

* Basic fix for #652
* Finishing work
* Added readme line
* Added test
* My test was stupid...
* Removed redundant lines
* That space...
This commit is contained in:
Stef Pletinck 2017-10-15 17:30:29 +02:00 committed by Pablo Aguiar
parent 2233e3679c
commit 64d6835e15
3 changed files with 52 additions and 0 deletions

View File

@ -196,6 +196,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `git_pull_clone` – clones instead of pulling when the repo does not exist;
* `git_pull_uncommitted_changes` – stashes changes before pulling and pops them afterwards;
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
* `git_push_different_branch_names` – fixes pushes when local brach name does not match remote branch name;
* `git_push_pull` – runs `git pull` when `push` was rejected;
* `git_push_without_commits` – Creates an initial commit if you forget and only `git add .`, when setting up a new project;
* `git_rebase_no_changes` – runs `git rebase --skip` instead of `git rebase --continue` when there are no changes;

View File

@ -0,0 +1,39 @@
import pytest
from thefuck.rules.git_push_different_branch_names import get_new_command, match
from thefuck.types import Command
output = """fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:%s
To push to the branch of the same name on the remote, use
git push origin %s
To choose either option permanently, see push.default in 'git help config'.
"""
def error_msg(localbranch, remotebranch):
return output % (remotebranch, localbranch)
def test_match():
assert match(Command('git push', error_msg('foo', 'bar')))
@pytest.mark.parametrize('command', [
Command('vim', ''),
Command('git status', error_msg('foo', 'bar')),
Command('git push', '')
])
def test_not_match(command):
assert not match(command)
def test_get_new_command():
new_command = get_new_command(Command('git push', error_msg('foo', 'bar')))
assert new_command == 'git push origin HEAD:bar'

View File

@ -0,0 +1,12 @@
import re
from thefuck.specific.git import git_support
@git_support
def match(command):
return "push" in command.script and "The upstream branch of your current branch does not match" in command.output
@git_support
def get_new_command(command):
return re.findall(r'^ +(git push [^\s]+ [^\s]+)', command.output, re.MULTILINE)[0]