diff --git a/README.md b/README.md index 0a106059..6d653537 100644 --- a/README.md +++ b/README.md @@ -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 ` commands replacing with the aliased command; diff --git a/tests/rules/test_git_direct_commit.py b/tests/rules/test_git_direct_commit.py new file mode 100644 index 00000000..6dc961e8 --- /dev/null +++ b/tests/rules/test_git_direct_commit.py @@ -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 diff --git a/thefuck/rules/git_direct_commit.py b/thefuck/rules/git_direct_commit.py new file mode 100644 index 00000000..57b37785 --- /dev/null +++ b/thefuck/rules/git_direct_commit.py @@ -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