@@ -56,6 +56,8 @@ class Git:
5656 # Use "tail +2" to remove the blank line at the top
5757 SHOW_ALL_FILE_HISTORY = 'git log --pretty="format:" --name-only | sort -u | tail +2'
5858
59+ READ_DEFAULT_BRANCH = "git config git-extras.default-branch"
60+
5961 def __init__ (self , context : Context ) -> None :
6062 self .context = context
6163
@@ -64,11 +66,8 @@ def current_branch(self) -> str:
6466 return run_stdout (self .context , "git branch --show-current" )
6567
6668 def default_branch (self ) -> str :
67- """Return the default branch name (master/main/develop/development)."""
68- return run_stdout (
69- self .context ,
70- "git branch -a | rg -o -e /master -e /develop.+ -e /main | sort -u | cut -b 2- | head -1" ,
71- )
69+ """Return the default branch nam as configured in git-extras.default-branch, if available."""
70+ return run_stdout (self .context , Git .READ_DEFAULT_BRANCH , warn = True , dry = False )
7271
7372 def checkout (self , * branches : str ) -> str :
7473 """Try checking out the specified branches in order."""
@@ -322,19 +321,18 @@ def merge_default(
322321
323322def set_default_branch (c : Context , remote : bool = False ) -> str :
324323 """Set the default branch config on the repo, if not configured yet."""
325- cmd_read_default_branch = "git config git-extras.default-branch"
326- default_branch = run_stdout (c , cmd_read_default_branch , warn = True , dry = False )
327- if not default_branch :
328- default_branch = run_with_fzf (
324+ branch = Git (c ).default_branch ()
325+ if not branch :
326+ branch = run_with_fzf (
329327 c ,
330328 "git branch --list" ,
331329 "--all" if remote else "" ,
332330 "| cut -b 3- | grep -v HEAD | sed -E 's#remotes/[^/]+/##g' | sort -u" ,
333331 )
334- run_command (c , cmd_read_default_branch , default_branch )
335- run_command (c , "git config init.defaultBranch" , default_branch )
332+ run_command (c , Git . READ_DEFAULT_BRANCH , branch )
333+ run_command (c , "git config init.defaultBranch" , branch )
336334 run_command (c , "git config --list | rg default.*branch" )
337- return default_branch
335+ return branch
338336
339337
340338@task (
0 commit comments