Skip to content

Commit 6de672c

Browse files
committed
Initial
1 parent 33ff6f9 commit 6de672c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

salt_bundle/release.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Release automation: detect, pack and publish formulas."""
22

3+
import os
34
import shutil
45
import subprocess
56
from datetime import datetime
@@ -234,6 +235,15 @@ def commit_index_to_branch(
234235
)
235236
current_branch = result.stdout.strip()
236237

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+
237247
# Check if target branch exists remotely
238248
result = subprocess.run(
239249
['git', 'ls-remote', '--heads', 'origin', branch_name],
@@ -290,12 +300,10 @@ def commit_index_to_branch(
290300
check=False
291301
)
292302

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():
299307
shutil.copy2(index_file, branch_index)
300308

301309
# Add index.yaml
@@ -355,8 +363,20 @@ def commit_index_to_branch(
355363
)
356364
except:
357365
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
358372
return False, f"Failed to commit index: {e.stderr}"
359373
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
360380
return False, "Git not found"
361381

362382

0 commit comments

Comments
 (0)