1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

Add git merge rule (#755)

This fixes https://github.com/nvbn/thefuck/issues/629
This commit is contained in:
David Hart 2018-01-02 16:47:48 +00:00 committed by Joseph Frazier
parent 897572d278
commit f700b23f57
3 changed files with 45 additions and 0 deletions

View File

@ -191,6 +191,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`); * `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`);
* `git_flag_after_filename` – fixes `fatal: bad flag '...' after filename` * `git_flag_after_filename` – fixes `fatal: bad flag '...' after filename`
* `git_help_aliased` &ndash; fixes `git help <alias>` commands replacing <alias> with the aliased command; * `git_help_aliased` &ndash; fixes `git help <alias>` commands replacing <alias> with the aliased command;
* `git_merge` &ndash; adds remote to branch names;
* `git_not_command` &ndash; fixes wrong git commands like `git brnch`; * `git_not_command` &ndash; fixes wrong git commands like `git brnch`;
* `git_pull` &ndash; sets upstream before executing previous `git pull`; * `git_pull` &ndash; sets upstream before executing previous `git pull`;
* `git_pull_clone` &ndash; clones instead of pulling when the repo does not exist; * `git_pull_clone` &ndash; clones instead of pulling when the repo does not exist;

View File

@ -0,0 +1,26 @@
import pytest
from thefuck.rules.git_merge import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return 'merge: local - not something we can merge\n\n' \
'Did you mean this?\n\tremote/local'
def test_match(output):
assert match(Command('git merge test', output))
assert not match(Command('git merge master', ''))
assert not match(Command('ls', output))
@pytest.mark.parametrize('command, new_command', [
(Command('git merge local', output()),
'git merge remote/local'),
(Command('git merge -m "test" local', output()),
'git merge -m "test" remote/local'),
(Command('git merge -m "test local" local', output()),
'git merge -m "test local" remote/local')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

View File

@ -0,0 +1,18 @@
import re
from thefuck.utils import replace_argument
from thefuck.specific.git import git_support
@git_support
def match(command):
return ('merge' in command.script
and ' - not something we can merge' in command.output
and 'Did you mean this?' in command.output)
@git_support
def get_new_command(command):
unknown_branch = re.findall(r'merge: (.+) - not something we can merge', command.output)[0]
remote_branch = re.findall(r'Did you mean this\?\n\t([^\n]+)', command.output)[0]
return replace_argument(command.script, unknown_branch, remote_branch)