launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #21248
[Merge] ~mitya57/git-build-recipe:master into git-build-recipe:master
Dmitry Shachnev has proposed merging ~mitya57/git-build-recipe:master into git-build-recipe:master.
Requested reviews:
Alberts Muktupāvels (albertsmuktupavels)
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1644640 in git-build-recipe: "Cannot nest-part into an existing directory"
https://bugs.launchpad.net/git-build-recipe/+bug/1644640
For more details, see:
https://code.launchpad.net/~mitya57/git-build-recipe/+git/git-build-recipe/+merge/311874
Make pull_or_clone work when the target dir exists and is empty. This allows one to use the nest command as a replacement for submodules.
Add two new tests for pull_or_clone function: one when the target directory is empty, and another one when it contains a subdirectory.
Fixes LP: #1644640.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~mitya57/git-build-recipe:master into git-build-recipe:master.
diff --git a/gitbuildrecipe/recipe.py b/gitbuildrecipe/recipe.py
index 3275775..d1700f2 100644
--- a/gitbuildrecipe/recipe.py
+++ b/gitbuildrecipe/recipe.py
@@ -295,6 +295,8 @@ insteadof = {
def pull_or_clone(base_branch, target_path):
"""Make target_path match base_branch, either by pulling or by cloning."""
base_branch.path = target_path
+ if os.path.exists(target_path) and not os.listdir(target_path):
+ os.rmdir(target_path)
if not os.path.exists(target_path):
os.makedirs(target_path)
base_branch.git_call("init")
diff --git a/gitbuildrecipe/tests/test_recipe.py b/gitbuildrecipe/tests/test_recipe.py
index c3c8491..ed7634d 100644
--- a/gitbuildrecipe/tests/test_recipe.py
+++ b/gitbuildrecipe/tests/test_recipe.py
@@ -543,7 +543,7 @@ class BuildTreeTests(GitTestCase):
source = GitRepository("source")
source.commit("one")
# We just create the target as a directory
- os.mkdir("target")
+ os.makedirs("target/junk")
base_branch = BaseRecipeBranch("source", "1", 0.2)
self.assertRaises(
TargetAlreadyExists, build_tree, base_branch, "target")
@@ -867,6 +867,30 @@ class BuildTreeTests(GitTestCase):
self.assertEqual(first_commit, target.rev_parse("one"))
self.assertEqual(["?? b"], target.status())
+ def test_pull_or_clone_branch_target_is_empty_dir(self):
+ source = GitRepository("source")
+ source.build_tree(["a"])
+ source.add(["a"])
+ commit = source.commit("one")
+ source.tag("one", commit)
+ base_branch = BaseRecipeBranch("source", "1", 0.2, revspec=commit)
+ os.mkdir("target")
+ pull_or_clone(base_branch, "target")
+ target = GitRepository("target", allow_create=False)
+ self.assertEqual(commit, target.last_revision())
+ self.assertEqual(commit, target.rev_parse("one"))
+
+ def test_pull_or_clone_branch_target_is_nonempty_dir(self):
+ source = GitRepository("source")
+ source.build_tree(["a"])
+ source.add(["a"])
+ commit = source.commit("one")
+ source.tag("one", commit)
+ base_branch = BaseRecipeBranch("source", "1", 0.2, revspec=commit)
+ os.makedirs("target/junk")
+ self.assertRaises(
+ TargetAlreadyExists, pull_or_clone, base_branch, "target")
+
def test_build_tree_runs_commands(self):
source = GitRepository("source")
commit = source.commit("one")