@@ -138,6 +138,28 @@ def is_new_version(formula: FormulaInfo, repo_index: Optional[Index]) -> bool:
138138 return formula .version not in existing_versions
139139
140140
141+ def find_git_root (path : Path ) -> Optional [Path ]:
142+ """Find git repository root from given path.
143+
144+ Args:
145+ path: Starting path to search from
146+
147+ Returns:
148+ Path to git root or None if not in a git repository
149+ """
150+ try :
151+ result = subprocess .run (
152+ ['git' , 'rev-parse' , '--show-toplevel' ],
153+ cwd = path ,
154+ capture_output = True ,
155+ text = True ,
156+ check = True
157+ )
158+ return Path (result .stdout .strip ())
159+ except (subprocess .CalledProcessError , FileNotFoundError ):
160+ return None
161+
162+
141163def create_git_tag (formula : FormulaInfo , formulas_dir : Path ) -> Tuple [bool , str ]:
142164 """Create git tag for formula release.
143165
@@ -383,17 +405,25 @@ def release_formulas(
383405 errors = [f"Failed to initialize GitHub releaser: { e } " ]
384406 return [], errors
385407
408+ # Find git repository root if index_branch is specified
409+ git_root = None
410+ if index_branch :
411+ git_root = find_git_root (repo_dir )
412+ if not git_root :
413+ errors = ["--index-branch requires a git repository" ]
414+ return [], errors
415+
386416 # Load existing repository index
387417 repo_index = None
388418 index_file = repo_dir / 'index.yaml'
389419
390420 # If index_branch is specified, try to load index from that branch first
391- if index_branch :
421+ if index_branch and git_root :
392422 try :
393423 # Check if branch exists and has index.yaml
394424 result = subprocess .run (
395425 ['git' , 'show' , f'{ index_branch } :index.yaml' ],
396- cwd = formulas_dir ,
426+ cwd = git_root ,
397427 capture_output = True ,
398428 text = True ,
399429 check = False
@@ -505,15 +535,15 @@ def release_formulas(
505535 print (f"Index updated: { len (index .packages )} packages total" )
506536
507537 # Commit index to separate branch if requested
508- if index_branch :
538+ if index_branch and git_root :
509539 if not asset_urls :
510540 print (f" Warning: --index-branch requires --github-release to upload assets" )
511541 else :
512542 index_file = repo_dir / 'index.yaml'
513543 success , message = commit_index_to_branch (
514544 index_file ,
515545 index_branch ,
516- formulas_dir ,
546+ git_root ,
517547 commit_message = f"Update index: { len (released )} package(s) released"
518548 )
519549 if success :
0 commit comments