summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-04-13 16:44:13 +0100
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-07-27 12:24:56 +0000
commitbd51a0b211995a3bf5eb62c51fbc76d652b8866f (patch)
treeb6fab0d991c7c8bd38001d394d02a44f72c9c1a9 /tests
parent84872141ea2465424d41dac9c6e3ea778ed798f8 (diff)
downloadbuildstream-bd51a0b211995a3bf5eb62c51fbc76d652b8866f.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.
Diffstat (limited to 'tests')
-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