Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Rule: Git commit with no added files #1131

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ following rules are enabled by default:
* `git_branch_0flag` – fixes commands such as `git branch 0v` and `git branch 0r` removing the created branch;
* `git_checkout` – fixes branch name or creates new branch;
* `git_clone_git_clone` – replaces `git clone git clone ...` with `git clone ...`
* `git_commit_add` – offers `git commit -a ...` or `git commit -p ...` after previous commit if it failed because nothing was staged;
* `git_commit_amend` – offers `git commit --amend` after previous commit;
* `git_commit_reset` – offers `git reset HEAD~` after previous commit;
* `git_diff_no_index` – adds `--no-index` to previous `git diff` on untracked files;
Expand Down
38 changes: 38 additions & 0 deletions tests/rules/test_git_commit_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from thefuck.rules.git_commit_add import match, get_new_command
from thefuck.types import Command


@pytest.mark.parametrize(
"script, output",
[
('git commit -m "test"', "no changes added to commit"),
("git commit", "no changes added to commit"),
],
)
def test_match(output, script):
assert match(Command(script, output))


@pytest.mark.parametrize(
"script, output",
[
('git commit -m "test"', " 1 file changed, 15 insertions(+), 14 deletions(-)"),
("git branch foo", ""),
("git checkout feature/test_commit", ""),
("git push", ""),
],
)
def test_not_match(output, script):
assert not match(Command(script, output))


@pytest.mark.parametrize(
"script, new_command",
[
("git commit", ["git commit -a", "git commit -p"]),
('git commit -m "foo"', ['git commit -a -m "foo"', 'git commit -p -m "foo"']),
],
)
def test_get_new_command(script, new_command):
assert get_new_command(Command(script, "")) == new_command
17 changes: 17 additions & 0 deletions thefuck/rules/git_commit_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from thefuck.utils import eager, replace_argument
from thefuck.specific.git import git_support


@git_support
def match(command):
return (
"commit" in command.script_parts
and "no changes added to commit" in command.output
)


@eager
@git_support
def get_new_command(command):
for opt in ("-a", "-p"):
yield replace_argument(command.script, "commit", "commit {}".format(opt))