Skip to content

Commit d000ec6

Browse files
committed
Erase local folder if branch to use differs from local active branch
1 parent eeed5ae commit d000ec6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

qgis_deployment_toolbelt/profiles/profiles_handler_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ def clone_or_pull(self, to_local_destination_path: Path, attempt: int = 1) -> Re
430430
raise_error=False,
431431
force_type="git_local",
432432
):
433+
# check if the active branch is the one to use
434+
# if not, remove the local folder and clone again
435+
local_branch = porcelain.active_branch(
436+
repo=Repo(root=f"{to_local_destination_path.resolve()}")
437+
).decode()
438+
if local_branch != self.DESTINATION_BRANCH_TO_USE:
439+
logger.debug(
440+
f"Local active branch ({local_branch}) "
441+
f"does not match the one to use ({self.DESTINATION_BRANCH_TO_USE})."
442+
)
443+
rmtree(path=to_local_destination_path, ignore_errors=True)
444+
return self.clone_or_pull(
445+
to_local_destination_path=to_local_destination_path
446+
)
433447
# FETCH
434448
logger.debug("Start fetching operations...")
435449
try:

0 commit comments

Comments
 (0)