mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
Merge pull request #569 from scorphus/rebase-skip
#N/A: Add `git_rebase_merge_dir` rule
This commit is contained in:
commit
4865bdd81f
@ -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`;
|
||||
|
40
tests/rules/test_git_rebase_merge_dir.py
Normal file
40
tests/rules/test_git_rebase_merge_dir.py
Normal file
@ -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
|
17
thefuck/rules/git_rebase_merge_dir.py
Normal file
17
thefuck/rules/git_rebase_merge_dir.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user