diff --git a/vcs2l/clients/git.py b/vcs2l/clients/git.py index 012fd69..7a456e8 100644 --- a/vcs2l/clients/git.py +++ b/vcs2l/clients/git.py @@ -325,7 +325,7 @@ def import_(self, command): cmd_fetch = [GitClient._executable, 'fetch', remote] if command.shallow: result_version_type, version_name = self._check_version_type( - command.url, checkout_version + command.url, checkout_version, command.retry ) if result_version_type['returncode']: return result_version_type @@ -398,7 +398,7 @@ def import_(self, command): version_type = None if command.version: result_version_type, version_name = self._check_version_type( - command.url, command.version + command.url, command.version, command.retry ) if result_version_type['returncode']: return result_version_type @@ -523,7 +523,7 @@ def _get_remote_urls(self): 'returncode': 0 if remote_urls else 1, } - def _check_version_type(self, url, version): + def _check_version_type(self, url, version, retry=0): # check if version starts with heads/ or tags/ prefixes = { 'heads/': 'branch', @@ -540,7 +540,7 @@ def _check_version_type(self, url, version): }, version[len(prefix) :] cmd = [GitClient._executable, 'ls-remote', url, version] - result = self._run_command(cmd) + result = self._run_command(cmd, retry=retry) if result['returncode']: result['output'] = ( 'Could not determine ref type of version: ' + result['output'] diff --git a/vcs2l/clients/vcs_base.py b/vcs2l/clients/vcs_base.py index b4beb18..50ebd36 100644 --- a/vcs2l/clients/vcs_base.py +++ b/vcs2l/clients/vcs_base.py @@ -1,10 +1,13 @@ import os import socket import subprocess +import sys import time from urllib.error import HTTPError, URLError from urllib.request import Request, urlopen +from vcs2l.executor import ansi + class VcsClientBase(object): type = None @@ -35,6 +38,13 @@ def _not_applicable(self, command, message=None): def _run_command(self, cmd, env=None, retry=0): for i in range(retry + 1): + if i > 0: + print( + ansi('yellowf') + + 'Retrying command (%d/%d): %s' % (i, retry, ' '.join(cmd)) + + ansi('reset'), + file=sys.stderr, + ) result = run_command(cmd, os.path.abspath(self.path), env=env) if not result['returncode']: # return successful result