Merge ~mitya57/git-build-recipe:master into git-build-recipe:master

Proposed by Dmitry Shachnev on 2016-11-26
Status: Merged
Merged at revision: b07a9bff06a0b4e95e5c932e1cae98fa459b1c65
Proposed branch: ~mitya57/git-build-recipe:master
Merge into: git-build-recipe:master
Diff against target: 57 lines (+27/-1)
2 files modified
gitbuildrecipe/recipe.py (+2/-0)
gitbuildrecipe/tests/test_recipe.py (+25/-1)
Reviewer Review Type Date Requested Status
Colin Watson 2016-11-26 Approve on 2016-11-29
Alberts Muktupāvels (community) 2016-11-26 Approve on 2016-11-26
Review via email: mp+311874@code.launchpad.net

Description of the Change

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.

To post a comment you must log in.
review: Approve
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitbuildrecipe/recipe.py b/gitbuildrecipe/recipe.py
2index 3275775..d1700f2 100644
3--- a/gitbuildrecipe/recipe.py
4+++ b/gitbuildrecipe/recipe.py
5@@ -295,6 +295,8 @@ insteadof = {
6 def pull_or_clone(base_branch, target_path):
7 """Make target_path match base_branch, either by pulling or by cloning."""
8 base_branch.path = target_path
9+ if os.path.exists(target_path) and not os.listdir(target_path):
10+ os.rmdir(target_path)
11 if not os.path.exists(target_path):
12 os.makedirs(target_path)
13 base_branch.git_call("init")
14diff --git a/gitbuildrecipe/tests/test_recipe.py b/gitbuildrecipe/tests/test_recipe.py
15index c3c8491..ed7634d 100644
16--- a/gitbuildrecipe/tests/test_recipe.py
17+++ b/gitbuildrecipe/tests/test_recipe.py
18@@ -543,7 +543,7 @@ class BuildTreeTests(GitTestCase):
19 source = GitRepository("source")
20 source.commit("one")
21 # We just create the target as a directory
22- os.mkdir("target")
23+ os.makedirs("target/junk")
24 base_branch = BaseRecipeBranch("source", "1", 0.2)
25 self.assertRaises(
26 TargetAlreadyExists, build_tree, base_branch, "target")
27@@ -867,6 +867,30 @@ class BuildTreeTests(GitTestCase):
28 self.assertEqual(first_commit, target.rev_parse("one"))
29 self.assertEqual(["?? b"], target.status())
30
31+ def test_pull_or_clone_branch_target_is_empty_dir(self):
32+ source = GitRepository("source")
33+ source.build_tree(["a"])
34+ source.add(["a"])
35+ commit = source.commit("one")
36+ source.tag("one", commit)
37+ base_branch = BaseRecipeBranch("source", "1", 0.2, revspec=commit)
38+ os.mkdir("target")
39+ pull_or_clone(base_branch, "target")
40+ target = GitRepository("target", allow_create=False)
41+ self.assertEqual(commit, target.last_revision())
42+ self.assertEqual(commit, target.rev_parse("one"))
43+
44+ def test_pull_or_clone_branch_target_is_nonempty_dir(self):
45+ source = GitRepository("source")
46+ source.build_tree(["a"])
47+ source.add(["a"])
48+ commit = source.commit("one")
49+ source.tag("one", commit)
50+ base_branch = BaseRecipeBranch("source", "1", 0.2, revspec=commit)
51+ os.makedirs("target/junk")
52+ self.assertRaises(
53+ TargetAlreadyExists, pull_or_clone, base_branch, "target")
54+
55 def test_build_tree_runs_commands(self):
56 source = GitRepository("source")
57 commit = source.commit("one")

Subscribers

People subscribed via source and target branches

to all changes: