|
1 | 1 | """Release automation: detect, pack and publish formulas.""" |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import shutil |
4 | 5 | import subprocess |
5 | 6 | from datetime import datetime |
@@ -234,6 +235,15 @@ def commit_index_to_branch( |
234 | 235 | ) |
235 | 236 | current_branch = result.stdout.strip() |
236 | 237 |
|
| 238 | + # Temporarily move index.yaml to avoid conflicts during checkout |
| 239 | + temp_index = None |
| 240 | + branch_index = repo_dir / 'index.yaml' |
| 241 | + if branch_index.exists() and index_file.resolve() == branch_index.resolve(): |
| 242 | + import tempfile |
| 243 | + temp_dir = Path(tempfile.gettempdir()) |
| 244 | + temp_index = temp_dir / f'index.yaml.tmp.{os.getpid()}' |
| 245 | + shutil.move(str(branch_index), str(temp_index)) |
| 246 | + |
237 | 247 | # Check if target branch exists remotely |
238 | 248 | result = subprocess.run( |
239 | 249 | ['git', 'ls-remote', '--heads', 'origin', branch_name], |
@@ -290,12 +300,10 @@ def commit_index_to_branch( |
290 | 300 | check=False |
291 | 301 | ) |
292 | 302 |
|
293 | | - # Copy index.yaml to branch root |
294 | | - import shutil |
295 | | - branch_index = repo_dir / 'index.yaml' |
296 | | - |
297 | | - # Only copy if source and destination are different |
298 | | - if index_file.resolve() != branch_index.resolve(): |
| 303 | + # Restore index.yaml from temp location or copy from source |
| 304 | + if temp_index and temp_index.exists(): |
| 305 | + shutil.move(str(temp_index), str(branch_index)) |
| 306 | + elif index_file.resolve() != branch_index.resolve(): |
299 | 307 | shutil.copy2(index_file, branch_index) |
300 | 308 |
|
301 | 309 | # Add index.yaml |
@@ -355,8 +363,20 @@ def commit_index_to_branch( |
355 | 363 | ) |
356 | 364 | except: |
357 | 365 | pass |
| 366 | + # Restore temp index if exists |
| 367 | + if temp_index and temp_index.exists(): |
| 368 | + try: |
| 369 | + shutil.move(str(temp_index), str(repo_dir / 'index.yaml')) |
| 370 | + except: |
| 371 | + pass |
358 | 372 | return False, f"Failed to commit index: {e.stderr}" |
359 | 373 | except FileNotFoundError: |
| 374 | + # Restore temp index if exists |
| 375 | + if temp_index and temp_index.exists(): |
| 376 | + try: |
| 377 | + shutil.move(str(temp_index), str(repo_dir / 'index.yaml')) |
| 378 | + except: |
| 379 | + pass |
360 | 380 | return False, "Git not found" |
361 | 381 |
|
362 | 382 |
|
|
0 commit comments