diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-24 15:46:40 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-25 10:45:10 +0000 |
commit | 13f28db3efb9f6f1bf1ef69302802137493bcc8c (patch) | |
tree | b473fde34f9edaa0669adde270be804abec30fb2 | |
parent | 791b9192ca6168a49cdc3a93bc322415d9668356 (diff) | |
download | import-13f28db3efb9f6f1bf1ef69302802137493bcc8c.tar.gz |
Clone source repo into tempdir
Extensions will now be given a path to a clone of the checkout
rather than a path to the checkout itself. This prevents untracked
modifications and protects any data the user might have in the
checkout dirs from the extensions themselves. It also helps prevent
a possible bug where the extension corrupts a checkout so that on
the second import the result differs from the first import.
Change-Id: I95d551a02aa77d665ba07fb7ed5b01be330e24d4
-rw-r--r-- | baserockimport/mainloop.py | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index a70981d..9aa38ff 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -222,54 +222,57 @@ class ImportLoop(object): self.app.settings['definitions-dir'], parent_metadata_filename) # 1. Make the source code available. - lorry = self._find_or_create_lorry_file(kind, name, version, parent_metadata_path) source_repo, repo_url = self._fetch_or_update_source(lorry) checked_out_version, ref = self._checkout_source_version_for_package( source_repo, package) - logging.debug('Checked out version: %s\tRef: %s', checked_out_version, ref) package.version_in_use = checked_out_version - repo_path = os.path.relpath(source_repo.dirname) - if morphlib.git.is_valid_sha1(ref): - self.app.status( - "%s %s: using %s commit %s", name, version, repo_path, ref) - else: - self.app.status( - "%s %s: using %s ref %s (commit %s)", name, version, repo_path, - ref, source_repo.resolve_ref_to_commit(ref)) + with morphlib.util.temp_dir() as td: + source_repo.clone_into(td, ref=ref) + temp_repo = morphlib.gitdir.GitDirectory(td) + repo_path = temp_repo.dirname + logging.debug('%s cloned to temporary repo at %s', + source_repo.dirname, repo_path) - # 2. Create a chunk morphology with build instructions. - sha1 = source_repo.resolve_ref_to_commit(ref) - chunk_morph = None - - if self.generate_chunk_morphs: - chunk_morph = self._find_or_create_chunk_morph( - kind, name, checked_out_version, - source_repo, repo_url, sha1) + if morphlib.git.is_valid_sha1(ref): + self.app.status("%s %s: using %s commit %s", + name, version, source_repo.dirname, ref) + else: + self.app.status("%s %s: using %s ref %s (commit %s)", + name, version, source_repo.dirname, + ref, temp_repo.resolve_ref_to_commit(ref)) - if self.app.settings['use-local-sources']: - package.repo_url = 'file://' + source_repo.dirname - else: - reponame = lorry.keys()[0] - package.repo_url = 'upstream:%s' % reponame + # 2. Create a chunk morphology with build instructions. + sha1 = temp_repo.resolve_ref_to_commit(ref) + chunk_morph = None - package.ref = sha1 - package.named_ref = ref + if self.generate_chunk_morphs: + chunk_morph = self._find_or_create_chunk_morph( + kind, name, checked_out_version, + temp_repo, repo_url, sha1) - package.morphology = chunk_morph + if self.app.settings['use-local-sources']: + package.repo_url = 'file://' + source_repo.dirname + else: + reponame = lorry.keys()[0] + package.repo_url = 'upstream:%s' % reponame - # 3. Calculate the dependencies of this package. + package.ref = sha1 + package.named_ref = ref + package.morphology = chunk_morph - dependencies = self._find_or_create_dependency_list( - kind, name, checked_out_version, source_repo, parent_metadata_path) + # 3. Calculate the dependencies of this package. + dependencies = self._find_or_create_dependency_list( + kind, name, checked_out_version, + temp_repo, parent_metadata_path) - package.dependencies = dependencies + package.dependencies = dependencies def _update_queue_and_graph(self, current_item, dependencies, to_process, processed, errors): |