mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 22:43:01 +00:00
maintainers/scripts/update.py: Fix worktree cleanup on failure
The context manager would previously just terminate early on exception. As a result, the worktree and branch would not get pruned when update script failed. Let’s wrap the cleanup code in `finally` block as suggested by Python docs: https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager
This commit is contained in:
parent
3c78e0ce04
commit
9fc19b0866
@ -91,9 +91,11 @@ def make_worktree() -> Generator[Tuple[str, str], None, None]:
|
||||
target_directory = f'{wt}/nixpkgs'
|
||||
|
||||
subprocess.run(['git', 'worktree', 'add', '-b', branch_name, target_directory])
|
||||
yield (target_directory, branch_name)
|
||||
subprocess.run(['git', 'worktree', 'remove', '--force', target_directory])
|
||||
subprocess.run(['git', 'branch', '-D', branch_name])
|
||||
try:
|
||||
yield (target_directory, branch_name)
|
||||
finally:
|
||||
subprocess.run(['git', 'worktree', 'remove', '--force', target_directory])
|
||||
subprocess.run(['git', 'branch', '-D', branch_name])
|
||||
|
||||
async def commit_changes(name: str, merge_lock: asyncio.Lock, worktree: str, branch: str, changes: List[Dict]) -> None:
|
||||
for change in changes:
|
||||
|
Loading…
Reference in New Issue
Block a user