11import os
2- import imp
2+ from importlib . machinery import SourceFileLoader
33
44
55class Config (object ):
66 BRANCH_PATTERN = r'^\w{2,3}/(\d+)'
77 COMMIT_PATTERN = '[#{story_num}] {message}'
8- BASE_BRANCH = 'master'
8+ BASE_BRANCH = None
99
1010 def __init__ (self ):
1111 self .load_rcfile (self .find_rcfile ())
12+ with os .popen ('git config repo.defaultbranch' ) as p :
13+ repo_default = p .read ().strip ()
1214 with os .popen ('git branch --list main' ) as p :
13- if p .read ().strip ():
14- Config .BASE_BRANCH = 'main'
15+ repo_main = p .read ().strip ()
16+ with os .popen ('git branch --list master' ) as p :
17+ repo_master = p .read ().strip ()
18+ with os .popen ('git config init.defaultbranch' ) as p :
19+ init_default = p .read ().strip ()
20+ self .BASE_BRANCH = repo_default or repo_main or repo_master or init_default or "master"
21+ if self .BASE_BRANCH .startswith ("* " ):
22+ self .BASE_BRANCH = self .BASE_BRANCH [2 :]
1523
1624 def find_rcfile (self ):
1725 with os .popen ('git rev-parse --show-toplevel' ) as p :
@@ -25,7 +33,7 @@ def find_rcfile(self):
2533 def load_rcfile (self , rcfile ):
2634 if rcfile is None :
2735 return
28- rc = imp . load_source ('devhelpers_rc' , rcfile )
36+ rc = SourceFileLoader ('devhelpers_rc' , rcfile ). load_module ( )
2937 for p in dir (rc ):
3038 if not p .startswith ('__' ):
3139 setattr (self , p , getattr (rc , p ))
0 commit comments