def test_nested_qiprojects(tmpdir):
    a_project = tmpdir.mkdir("a")
    a_project.mkdir(".git")
    worktree_xml = tmpdir.mkdir(".qi").join("worktree.xml")
    worktree_xml.write("""
<worktree>
    <project src="a" />
</worktree>
""")

    a_xml = a_project.join("qiproject.xml")
    a_xml.write("""
<project name="a">
    <project src="b" />
</project>
""")

    b_project = a_project.mkdir("b")
    b_xml = b_project.join("qiproject.xml")
    b_xml.write("""
<project name="b">
    <project src="c" />
</project>
""")

    c_project = b_project.mkdir("c")
    c_xml = c_project.join("qiproject.xml")
    c_xml.write('<project name="c" />\n')

    worktree = qisrc.worktree.open_worktree(tmpdir.strpath)
    assert len(worktree.projects) == 3
    a_proj = worktree.get_project("a")
    c_proj = worktree.get_project("a/b/c")
    assert c_proj.git_project.src == a_proj.src
def test_guess_current_project(tmpdir):
    worktree = create_worktree(tmpdir)

    # Simple check
    bar_src = tmpdir.join("lib").join("libbar").join("src")
    cur_proj = qisrc.cmdparse.guess_current_project(worktree, bar_src.strpath)
    assert cur_proj.src == worktree.get_project("lib/libbar").src

    # Should return the most nested project
    eggs_src = tmpdir.join("spam").join("eggs").join("src")
    cur_proj = qisrc.cmdparse.guess_current_project(worktree, eggs_src.strpath)
    assert cur_proj.src == worktree.get_project("spam/eggs").src

    # Should return None
    other = tmpdir.join("other")
    assert qisrc.cmdparse.guess_current_project(worktree, other.strpath) is None
 def test_add_project(self):
     xml = "<worktree />"
     worktree = self.create_worktee(xml)
     worktree.add_project("foo")
     self.assertEquals(len(worktree.projects), 1)
     foo = worktree.get_project("foo")
     self.assertEquals(foo.src, "foo")
    def test_add_git_project(self):
        xml = "<worktree />"
        worktree = self.create_worktee(xml)
        worktree.add_project("foo")
        qibuild.sh.mkdir(
            os.path.join(self.tmp, "foo", ".git"),
            recursive=True)

        # Re-open worktre, check that foo is in git_projects
        worktree = qisrc.open_worktree(self.tmp)
        self.assertEquals(len(worktree.git_projects), 1)
        git_foo = worktree.get_project("foo")
        self.assertEquals(git_foo.src, "foo")
 def test_remove_project(self):
     xml = "<worktree />"
     worktree = self.create_worktee(xml)
     foo_src = os.path.join(worktree.root, "foo")
     qibuild.sh.mkdir(foo_src)
     worktree.add_project("foo")
     self.assertEquals(len(worktree.projects), 1)
     foo = worktree.get_project("foo")
     self.assertEquals(foo.src, "foo")
     error = None
     try:
         worktree.remove_project("bar")
     except Exception, e:
         error = e
예제 #6
0
def parse_project_arg(worktree, project_arg, single=False):
    """ Used to parse one 'project arg'
    Can be :
        * an absolute path
        * the path of the project relative to the worktree
    Result will be:
        * all the projects in the given subdir (unles single is True)
        * a project returned by worktree.get_project()

    """
    if not single:
        as_path = qibuild.sh.to_native_path(project_arg)
        if os.path.exists(as_path):
            res = projects_in_subdir(worktree, as_path, raises=True)
            return res

    # Now assume it is a project src
    project = worktree.get_project(project_arg, raises=True)
    return [project]