File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ` ;
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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" )
You can’t perform that action at this time.
0 commit comments