summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@gmail.com>2016-10-28 14:27:43 +0200
committerSebastian Schuberth <sschuberth@gmail.com>2016-10-28 14:43:02 +0200
commit27226e742d7e1a3d371531c19a3fdd91a4f9ab4a (patch)
treed22b18a2dcc496705deb46b675a8ec13e8cbaca8
parent7a77c16d376f504bd06d017ba10c91e3a6073b08 (diff)
downloadgit-repo-27226e742d7e1a3d371531c19a3fdd91a4f9ab4a.tar.gz
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
-rwxr-xr-xrepo9
1 files changed, 8 insertions, 1 deletions
diff --git a/repo b/repo
index f9eb9e8a..36af5114 100755
--- a/repo
+++ b/repo
@@ -344,6 +344,10 @@ def _Init(args, gitc_init=False):
344 dst = os.path.abspath(os.path.join(repodir, S_repo)) 344 dst = os.path.abspath(os.path.join(repodir, S_repo))
345 _Clone(url, dst, opt.quiet, not opt.no_clone_bundle) 345 _Clone(url, dst, opt.quiet, not opt.no_clone_bundle)
346 346
347 if not os.path.isfile('%s/repo' % dst):
348 _print("warning: '%s' does not look like a git-repo repository, is "
349 "REPO_URL set correctly?" % url, file=sys.stderr)
350
347 if can_verify and not opt.no_repo_verify: 351 if can_verify and not opt.no_repo_verify:
348 rev = _Verify(dst, branch, opt.quiet) 352 rev = _Verify(dst, branch, opt.quiet)
349 else: 353 else:
@@ -850,7 +854,10 @@ def main(orig_args):
850 try: 854 try:
851 _Init(args, gitc_init=(cmd == 'gitc-init')) 855 _Init(args, gitc_init=(cmd == 'gitc-init'))
852 except CloneFailure: 856 except CloneFailure:
853 shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) 857 path = os.path.join(repodir, S_repo)
858 _print("fatal: cloning the git-repo repository failed, will remove "
859 "'%s' " % path, file=sys.stderr)
860 shutil.rmtree(path, ignore_errors=True)
854 sys.exit(1) 861 sys.exit(1)
855 repo_main, rel_repo_dir = _FindRepo() 862 repo_main, rel_repo_dir = _FindRepo()
856 else: 863 else: