import time
from .config import config
-from .contextutil import safe_while
+from .contextutil import safe_while, MaxWhileTries
from .exceptions import BootstrapError, BranchNotFoundError, GitError
log = logging.getLogger(__name__)
lock_path = dest_path.rstrip('/') + '.lock'
with FileLock(lock_path, noop=not lock):
with safe_while(sleep=10, tries=60) as proceed:
- while proceed():
- try:
- enforce_repo_state(url, dest_path,
- branch)
- if bootstrap:
- bootstrap(dest_path)
- break
- except GitError:
- log.exception("Git error encountered; retrying")
- except BootstrapError:
- log.exception("Bootstrap error encountered; retrying")
+ try:
+ while proceed():
+ try:
+ enforce_repo_state(url, dest_path, branch)
+ if bootstrap:
+ bootstrap(dest_path)
+ break
+ except GitError:
+ log.exception("Git error encountered; retrying")
+ except BootstrapError:
+ log.exception("Bootstrap error encountered; retrying")
+ except MaxWhileTries:
+ shutil.rmtree(dest_path, ignore_errors=True)
+ raise
return dest_path