diff --git a/README.md b/README.md index 350b1a58..0d2d7f56 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,7 @@ following rules are enabled by default: * `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; +* `git_hook_bypass` – adds `--no-verify` flag previous to `git am`, `git commit`, or `git push` command; * `git_lfs_mistype` – fixes mistyped `git lfs ` commands; * `git_merge` – adds remote to branch names; * `git_merge_unrelated` – adds `--allow-unrelated-histories` when required diff --git a/tests/rules/test_git_hook_bypass.py b/tests/rules/test_git_hook_bypass.py new file mode 100644 index 00000000..8cd8715a --- /dev/null +++ b/tests/rules/test_git_hook_bypass.py @@ -0,0 +1,43 @@ +import pytest +from thefuck.rules.git_hook_bypass import match, get_new_command +from thefuck.types import Command + + +@pytest.mark.parametrize( + "command", + [ + Command("git am", ""), + Command("git commit", ""), + Command("git commit -m 'foo bar'", ""), + Command("git push", ""), + Command("git push -u foo bar", ""), + ], +) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize( + "command", + [ + Command("git add foo", ""), + Command("git status", ""), + Command("git diff foo bar", ""), + ], +) +def test_not_match(command): + assert not match(command) + + +@pytest.mark.parametrize( + "command, new_command", + [ + (Command("git am", ""), "git am --no-verify"), + (Command("git commit", ""), "git commit --no-verify"), + (Command("git commit -m 'foo bar'", ""), "git commit --no-verify -m 'foo bar'"), + (Command("git push", ""), "git push --no-verify"), + (Command("git push -p", ""), "git push --no-verify -p"), + ], +) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/git_hook_bypass.py b/thefuck/rules/git_hook_bypass.py new file mode 100644 index 00000000..ce479f80 --- /dev/null +++ b/thefuck/rules/git_hook_bypass.py @@ -0,0 +1,27 @@ +from thefuck.utils import replace_argument +from thefuck.specific.git import git_support + +hooked_commands = ("am", "commit", "push") + + +@git_support +def match(command): + return any( + hooked_command in command.script_parts for hooked_command in hooked_commands + ) + + +@git_support +def get_new_command(command): + hooked_command = next( + hooked_command + for hooked_command in hooked_commands + if hooked_command in command.script_parts + ) + return replace_argument( + command.script, hooked_command, hooked_command + " --no-verify" + ) + + +priority = 900 +requires_output = False