mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00: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:
parent
2233e3679c
commit
64d6835e15
@ -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;
|
||||
|
39
tests/rules/test_git_push_different_branch_names.py
Normal file
39
tests/rules/test_git_push_different_branch_names.py
Normal 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'
|
12
thefuck/rules/git_push_different_branch_names.py
Normal file
12
thefuck/rules/git_push_different_branch_names.py
Normal 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]
|
Loading…
x
Reference in New Issue
Block a user