summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-04-13 16:44:13 +0100
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-07-29 17:12:42 +0900
commit4ee3856ca8314a2b32bf2d12fd724db0edce2f80 (patch)
treeb3ab9b364a7dfa88cc0bcca009c5e095932ee791
parent81349e1b0c5671b91f5ec91e4fa842e7b4a2a0f8 (diff)
downloadbuildstream-4ee3856ca8314a2b32bf2d12fd724db0edce2f80.tar.gz
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.
-rw-r--r--tests/testutils/repo/repo.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/testutils/repo/repo.py b/tests/testutils/repo/repo.py
index 4c9ee59a9..234aa374c 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