This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch jonathan/mirror-client-sourcedownloader-tidy in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit a18e63716f7d6cc949cc4a48cd68edc6d74715e6 Author: Jonathan Maw <[email protected]> AuthorDate: Fri Apr 13 16:44:13 2018 +0100 testutils: Add a helper to copy a testutils repo This is helpful if you want to test what happens when you have one repo that has diverged from another. By copying the repo you're sure they start with shared history. This is especially useful when mirroring. --- tests/testutils/repo/repo.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/testutils/repo/repo.py b/tests/testutils/repo/repo.py index 4c9ee59..234aa37 100644 --- a/tests/testutils/repo/repo.py +++ b/tests/testutils/repo/repo.py @@ -22,7 +22,7 @@ class Repo(): # The directory the actual repo will be stored in self.repo = os.path.join(self.directory, subdir) - os.makedirs(self.repo) + os.makedirs(self.repo, exist_ok=True) # create(): # @@ -69,3 +69,22 @@ class Repo(): shutil.copytree(src_path, dest_path) else: shutil.copy2(src_path, dest_path) + + # copy(): + # + # Creates a copy of this repository in the specified + # destination. + # + # Args: + # dest (str): The destination directory + # + # Returns: + # (Repo): A Repo object for the new repository. + def copy(self, dest): + subdir = self.repo[len(self.directory):].lstrip(os.sep) + new_dir = os.path.join(dest, subdir) + os.makedirs(new_dir, exist_ok=True) + self.copy_directory(self.repo, new_dir) + repo_type = type(self) + new_repo = repo_type(dest, subdir) + return new_repo
