diff --git a/README.md b/README.md index aedaf1b2..f2676077 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `git_rebase_no_changes` – runs `git rebase --skip` instead of `git rebase --continue` when there are no changes; * `git_rm_local_modifications` – adds `-f` or `--cached` when you try to `rm` a locally modified file; * `git_rm_recursive` – adds `-r` when you try to `rm` a directory; +* `git_rebase_merge_dir` – offers `git rebase (--continue | --abort | --skip)` or removing the `.git/rebase-merge` dir when a rebase is in progress; * `git_remote_seturl_add` – runs `git remote add` when `git remote set_url` on nonexistant remote; * `git_stash` – stashes you local modifications before rebasing or switching branch; * `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`; diff --git a/tests/rules/test_git_rebase_merge_dir.py b/tests/rules/test_git_rebase_merge_dir.py new file mode 100644 index 00000000..3e43ea70 --- /dev/null +++ b/tests/rules/test_git_rebase_merge_dir.py @@ -0,0 +1,40 @@ +import pytest +from thefuck.rules.git_rebase_merge_dir import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def stderr(): + return ('\n\nIt seems that there is already a rebase-merge directory, and\n' + 'I wonder if you are in the middle of another rebase. If that is the\n' + 'case, please try\n' + '\tgit rebase (--continue | --abort | --skip)\n' + 'If that is not the case, please\n' + '\trm -fr "/foo/bar/baz/egg/.git/rebase-merge"\n' + 'and run me again. I am stopping in case you still have something\n' + 'valuable there.\n') + + +@pytest.mark.parametrize('script', [ + ('git rebase master'), ('git rebase -skip'), ('git rebase')]) +def test_match(stderr, script): + assert match(Command(script=script, stderr=stderr)) + + +@pytest.mark.parametrize('script', ['git rebase master', 'git rebase -abort']) +def test_not_match(script): + assert not match(Command(script=script)) + + +@pytest.mark.parametrize('script, result', [ + ('git rebase master', [ + 'git rebase --abort', 'git rebase --skip', 'git rebase --continue', + 'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"']), + ('git rebase -skip', [ + 'git rebase --skip', 'git rebase --abort', 'git rebase --continue', + 'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"']), + ('git rebase', [ + 'git rebase --skip', 'git rebase --abort', 'git rebase --continue', + 'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"'])]) +def test_get_new_command(stderr, script, result): + assert get_new_command(Command(script=script, stderr=stderr)) == result diff --git a/thefuck/rules/git_rebase_merge_dir.py b/thefuck/rules/git_rebase_merge_dir.py new file mode 100644 index 00000000..910e3121 --- /dev/null +++ b/thefuck/rules/git_rebase_merge_dir.py @@ -0,0 +1,17 @@ +from difflib import get_close_matches +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return (' rebase' in command.script and + 'It seems that there is already a rebase-merge directory' in command.stderr and + 'I wonder if you are in the middle of another rebase' in command.stderr) + + +@git_support +def get_new_command(command): + command_list = ['git rebase --continue', 'git rebase --abort', 'git rebase --skip'] + rm_cmd = command.stderr.split('\n')[-4] + command_list.append(rm_cmd.strip()) + return get_close_matches(command.script, command_list, 4, 0)