1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#1184: Add new rule for main / master Git branches

This commit is contained in:
Dave Storey 2021-04-06 14:50:43 +01:00 committed by Pablo Santiago Blum de Aguiar
parent 11b70526f7
commit 70a42b54ab
3 changed files with 38 additions and 0 deletions

View File

@ -244,6 +244,7 @@ following rules are enabled by default:
* `git_help_aliased` &ndash; fixes `git help <alias>` commands replacing <alias> with the aliased command;
* `git_hook_bypass` &ndash; adds `--no-verify` flag previous to `git am`, `git commit`, or `git push` command;
* `git_lfs_mistype` &ndash; fixes mistyped `git lfs <command>` commands;
* `git_main_master` &ndash; fixes incorrect branch name between `main` and `master`
* `git_merge` &ndash; adds remote to branch names;
* `git_merge_unrelated` &ndash; adds `--allow-unrelated-histories` when required
* `git_not_command` &ndash; fixes wrong git commands like `git brnch`;

View File

@ -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

View File

@ -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")