mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-27 15:28:56 +00:00
add new rule
This commit is contained in:
parent
d8ddf5a2be
commit
5314f6b831
@ -239,6 +239,7 @@ following rules are enabled by default:
|
||||
* `git_commit_reset` – offers `git reset HEAD~` after previous commit;
|
||||
* `git_diff_no_index` – adds `--no-index` to previous `git diff` on untracked files;
|
||||
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
||||
* `git_direct_commit` – adds the files to the staged level, in case that the user tries to commit some changes but has forgotten this step;
|
||||
* `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`);
|
||||
* `git_flag_after_filename` – fixes `fatal: bad flag '...' after filename`
|
||||
* `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command;
|
||||
|
28
tests/rules/test_git_direct_commit.py
Normal file
28
tests/rules/test_git_direct_commit.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from thefuck.rules.git_direct_commit import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output",
|
||||
[('''git commit -m "make an other commit"''', "Changes not staged for commit")]
|
||||
)
|
||||
def test_match(script, output):
|
||||
assert match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output",
|
||||
[('''git commit -m "make a commit"''', "")]
|
||||
)
|
||||
def test_not_match(script, output):
|
||||
assert not match(Command(script, output))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"script, output, new_command",
|
||||
[("git commit -m 'make a commit'", "Untracked files", "git add --all && git commit -m 'make a commit'")]
|
||||
)
|
||||
def test_get_new_command(script, output, new_command):
|
||||
assert get_new_command(Command(script, output)) == new_command
|
10
thefuck/rules/git_direct_commit.py
Normal file
10
thefuck/rules/git_direct_commit.py
Normal file
@ -0,0 +1,10 @@
|
||||
def match(command):
|
||||
return ('Untracked files' in command.output or '''use "git add"''' in command.output
|
||||
or 'Changes not staged for commit' in command.output)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return 'git add --all && ' + command.script
|
||||
|
||||
|
||||
priority = 900
|
Loading…
x
Reference in New Issue
Block a user