@@ -244,10 +244,12 @@ impl Config {
244244 // For bare repositories:
245245 // Get the default branch name from HEAD
246246 let default_branch = if let Ok ( head) = repo. head ( ) {
247- head. shorthand ( ) . unwrap_or ( "main" ) . to_string ( )
247+ head. shorthand ( )
248+ . unwrap_or ( crate :: constants:: DEFAULT_BRANCH_MAIN )
249+ . to_string ( )
248250 } else {
249251 // Fallback to common default branch names
250- "main" . to_string ( )
252+ crate :: constants :: DEFAULT_BRANCH_MAIN . to_string ( )
251253 } ;
252254
253255 if let Ok ( cwd) = std:: env:: current_dir ( ) {
@@ -264,17 +266,12 @@ impl Config {
264266 }
265267
266268 // Also check main/master if different from default
267- if default_branch != "main" {
268- let main_config = cwd. join ( "main" ) . join ( CONFIG_FILE_NAME ) ;
269- if main_config. exists ( ) {
270- return Self :: load_from_file ( & main_config, repo) ;
271- }
272- }
273- if default_branch != "master" {
274- let master_config = cwd. join ( "master" ) . join ( CONFIG_FILE_NAME ) ;
275- if master_config. exists ( ) {
276- return Self :: load_from_file ( & master_config, repo) ;
277- }
269+ if let Some ( config_path) = crate :: utils:: find_config_in_default_branches (
270+ & cwd,
271+ & default_branch,
272+ CONFIG_FILE_NAME ,
273+ ) {
274+ return Self :: load_from_file ( & config_path, repo) ;
278275 }
279276
280277 // 2. Try to detect worktree pattern by listing existing worktrees
@@ -312,27 +309,25 @@ impl Config {
312309 }
313310
314311 // Fallback to main/master
315- if default_branch != "main" {
316- let main_config =
317- first_parent. join ( "main" ) . join ( CONFIG_FILE_NAME ) ;
318- if main_config. exists ( ) {
319- return Self :: load_from_file ( & main_config, repo) ;
320- }
321- }
322- if default_branch != "master" {
323- let master_config =
324- first_parent. join ( "master" ) . join ( CONFIG_FILE_NAME ) ;
325- if master_config. exists ( ) {
326- return Self :: load_from_file ( & master_config, repo) ;
327- }
312+ if let Some ( config_path) =
313+ crate :: utils:: find_config_in_default_branches (
314+ first_parent,
315+ & default_branch,
316+ CONFIG_FILE_NAME ,
317+ )
318+ {
319+ return Self :: load_from_file ( & config_path, repo) ;
328320 }
329321 }
330322 }
331323 }
332324 }
333325
334326 // 3. Fallback: Check common subdirectories
335- for subdir in & [ "branch" , "worktrees" ] {
327+ for subdir in & [
328+ crate :: constants:: BRANCH_SUBDIR ,
329+ crate :: constants:: WORKTREES_SUBDIR ,
330+ ] {
336331 let branch_path = cwd
337332 . join ( subdir)
338333 . join ( & default_branch)
@@ -364,7 +359,10 @@ impl Config {
364359
365360 // 2. Then check main/master default branch worktree
366361 // Check if current directory is named "worktrees" or inside a worktree
367- if cwd. file_name ( ) . is_some_and ( |n| n == "worktrees" ) {
362+ if cwd
363+ . file_name ( )
364+ . is_some_and ( |n| n == crate :: constants:: WORKTREES_SUBDIR )
365+ {
368366 // We're in the worktrees directory itself
369367 if let Some ( parent) = cwd. parent ( ) {
370368 let main_config = parent. join ( CONFIG_FILE_NAME ) ;
@@ -378,7 +376,10 @@ impl Config {
378376 // This is a linked worktree, find the main/master worktree
379377 if let Some ( parent) = cwd. parent ( ) {
380378 // Check if we're in a worktrees subdirectory
381- if parent. file_name ( ) . is_some_and ( |n| n == "worktrees" ) {
379+ if parent
380+ . file_name ( )
381+ . is_some_and ( |n| n == crate :: constants:: WORKTREES_SUBDIR )
382+ {
382383 // Go up one more level to repository root
383384 if let Some ( repo_root) = parent. parent ( ) {
384385 // Check for main worktree
@@ -388,25 +389,32 @@ impl Config {
388389 }
389390
390391 // Also check main/master subdirectories
391- let main_path = repo_root. join ( "main" ) . join ( CONFIG_FILE_NAME ) ;
392+ let main_path = repo_root
393+ . join ( crate :: constants:: DEFAULT_BRANCH_MAIN )
394+ . join ( CONFIG_FILE_NAME ) ;
392395 if main_path. exists ( ) {
393396 return Self :: load_from_file ( & main_path, repo) ;
394397 }
395398
396- let master_path =
397- repo_root. join ( "master" ) . join ( CONFIG_FILE_NAME ) ;
399+ let master_path = repo_root
400+ . join ( crate :: constants:: DEFAULT_BRANCH_MASTER )
401+ . join ( CONFIG_FILE_NAME ) ;
398402 if master_path. exists ( ) {
399403 return Self :: load_from_file ( & master_path, repo) ;
400404 }
401405 }
402406 } else {
403407 // Not in worktrees subdirectory, check parent for main/master
404- let main_path = parent. join ( "main" ) . join ( CONFIG_FILE_NAME ) ;
408+ let main_path = parent
409+ . join ( crate :: constants:: DEFAULT_BRANCH_MAIN )
410+ . join ( CONFIG_FILE_NAME ) ;
405411 if main_path. exists ( ) {
406412 return Self :: load_from_file ( & main_path, repo) ;
407413 }
408414
409- let master_path = parent. join ( "master" ) . join ( CONFIG_FILE_NAME ) ;
415+ let master_path = parent
416+ . join ( crate :: constants:: DEFAULT_BRANCH_MASTER )
417+ . join ( CONFIG_FILE_NAME ) ;
410418 if master_path. exists ( ) {
411419 return Self :: load_from_file ( & master_path, repo) ;
412420 }
0 commit comments