diff --git a/README.md b/README.md index 95f0206..18c589e 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,7 @@ following rules are enabled by default: * `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_main_master` – fixes incorrect branch name between `main` and `master` * `git_merge` – adds remote to branch names; * `git_merge_unrelated` – adds `--allow-unrelated-histories` when required * `git_not_command` – fixes wrong git commands like `git brnch`; diff --git a/tests/rules/test_git_main_master.py b/tests/rules/test_git_main_master.py new file mode 100644 index 0000000..7e57334 --- /dev/null +++ b/tests/rules/test_git_main_master.py @@ -0,0 +1,23 @@ +import pytest +from thefuck.rules.git_main_master import match, get_new_command +from thefuck.types import Command + + +output = 'error: pathspec \'%s\' did not match any file(s) known to git' + + +def test_match(): + assert match(Command('git checkout main', output % ('main'))) + assert match(Command('git checkout master', output % ('master'))) + assert not match(Command('git checkout master', '')) + assert not match(Command('git checkout main', '')) + assert not match(Command('git checkout wibble', output % ('wibble'))) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('git checkout main', output % ('main')), + 'git checkout master'), + (Command('git checkout master', output % ('master')), + 'git checkout main')]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/git_main_master.py b/thefuck/rules/git_main_master.py new file mode 100644 index 0000000..4879fc3 --- /dev/null +++ b/thefuck/rules/git_main_master.py @@ -0,0 +1,14 @@ +from thefuck.specific.git import git_support + + +@git_support +def match(command): + return "'master'" in command.output.lower() or "'main'" in command.output.lower() + + +@git_support +def get_new_command(command): + if "'master'" in command.output.lower(): + return command.script.replace("master", "main") + else: + return command.script.replace("main", "master")