Skip to content

Commit 227e109

Browse files
storey247scorphus
authored andcommitted
nvbn#1184: Add new rule for main / master Git branches
1 parent fe19428 commit 227e109

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ following rules are enabled by default:
243243
* `git_help_aliased` &ndash; fixes `git help <alias>` commands replacing <alias> with the aliased command;
244244
* `git_hook_bypass` &ndash; adds `--no-verify` flag previous to `git am`, `git commit`, or `git push` command;
245245
* `git_lfs_mistype` &ndash; fixes mistyped `git lfs <command>` commands;
246+
* `git_main_master` &ndash; fixes incorrect branch name between `main` and `master`
246247
* `git_merge` &ndash; adds remote to branch names;
247248
* `git_merge_unrelated` &ndash; adds `--allow-unrelated-histories` when required
248249
* `git_not_command` &ndash; fixes wrong git commands like `git brnch`;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
from thefuck.rules.git_main_master import match, get_new_command
3+
from thefuck.types import Command
4+
5+
6+
output = 'error: pathspec \'%s\' did not match any file(s) known to git'
7+
8+
9+
def test_match():
10+
assert match(Command('git checkout main', output % ('main')))
11+
assert match(Command('git checkout master', output % ('master')))
12+
assert not match(Command('git checkout master', ''))
13+
assert not match(Command('git checkout main', ''))
14+
assert not match(Command('git checkout wibble', output % ('wibble')))
15+
16+
17+
@pytest.mark.parametrize('command, new_command', [
18+
(Command('git checkout main', output % ('main')),
19+
'git checkout master'),
20+
(Command('git checkout master', output % ('master')),
21+
'git checkout main')])
22+
def test_get_new_command(command, new_command):
23+
assert get_new_command(command) == new_command

thefuck/rules/git_main_master.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from thefuck.specific.git import git_support
2+
3+
4+
@git_support
5+
def match(command):
6+
return "'master'" in command.output.lower() or "'main'" in command.output.lower()
7+
8+
9+
@git_support
10+
def get_new_command(command):
11+
if "'master'" in command.output.lower():
12+
return command.script.replace("master", "main")
13+
else:
14+
return command.script.replace("main", "master")

0 commit comments

Comments
 (0)