mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#1184: Add new rule for main / master Git branches
This commit is contained in:
parent
11b70526f7
commit
70a42b54ab
@ -244,6 +244,7 @@ following rules are enabled by default:
|
|||||||
* `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command;
|
* `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command;
|
||||||
* `git_hook_bypass` – adds `--no-verify` flag previous to `git am`, `git commit`, or `git push` 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 <command>` commands;
|
* `git_lfs_mistype` – fixes mistyped `git lfs <command>` commands;
|
||||||
|
* `git_main_master` – fixes incorrect branch name between `main` and `master`
|
||||||
* `git_merge` – adds remote to branch names;
|
* `git_merge` – adds remote to branch names;
|
||||||
* `git_merge_unrelated` – adds `--allow-unrelated-histories` when required
|
* `git_merge_unrelated` – adds `--allow-unrelated-histories` when required
|
||||||
* `git_not_command` – fixes wrong git commands like `git brnch`;
|
* `git_not_command` – fixes wrong git commands like `git brnch`;
|
||||||
|
23
tests/rules/test_git_main_master.py
Normal file
23
tests/rules/test_git_main_master.py
Normal 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
|
14
thefuck/rules/git_main_master.py
Normal file
14
thefuck/rules/git_main_master.py
Normal 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")
|
Loading…
x
Reference in New Issue
Block a user