Add a check and more output to protect against invalid REPO_URLs

If you don't know that the url to git-repo itself can be overridden via
REPO_URL, it's hard to debug cases where REPO_URL is accidentally set to
another repository, e.g. inside a Jenkins CI job. What makes is even
harder is that the ".repo/repo" directory gets silently removed in such
cases as verifications fails, which makes it impossible to look at the
cloned files to understand the problem.

To better protect against such an issue, warn if the cloned git-repo
repository does not contain a top-level "repo" file, and state that the
".repo/repo" directory will be removed in case of a clone failure.

Change-Id: I697b4999205a5967910c0237772ccaada01e74d4
This commit is contained in:
Sebastian Schuberth 2016-10-28 14:27:43 +02:00
parent 7a77c16d37
commit 27226e742d

9
repo
View File

@ -344,6 +344,10 @@ def _Init(args, gitc_init=False):
dst = os.path.abspath(os.path.join(repodir, S_repo)) dst = os.path.abspath(os.path.join(repodir, S_repo))
_Clone(url, dst, opt.quiet, not opt.no_clone_bundle) _Clone(url, dst, opt.quiet, not opt.no_clone_bundle)
if not os.path.isfile('%s/repo' % dst):
_print("warning: '%s' does not look like a git-repo repository, is "
"REPO_URL set correctly?" % url, file=sys.stderr)
if can_verify and not opt.no_repo_verify: if can_verify and not opt.no_repo_verify:
rev = _Verify(dst, branch, opt.quiet) rev = _Verify(dst, branch, opt.quiet)
else: else:
@ -850,7 +854,10 @@ def main(orig_args):
try: try:
_Init(args, gitc_init=(cmd == 'gitc-init')) _Init(args, gitc_init=(cmd == 'gitc-init'))
except CloneFailure: except CloneFailure:
shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) path = os.path.join(repodir, S_repo)
_print("fatal: cloning the git-repo repository failed, will remove "
"'%s' " % path, file=sys.stderr)
shutil.rmtree(path, ignore_errors=True)
sys.exit(1) sys.exit(1)
repo_main, rel_repo_dir = _FindRepo() repo_main, rel_repo_dir = _FindRepo()
else: else: