コード例 #1
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_git_manifest_sync(self):
        create_git_repo(self.tmp, "qi/libqi")
        manifest_url = create_git_repo(self.tmp, "manifest.git")
        xml = """
<manifest>
    <remote name="origin"
        fetch="{tmp}/srv"
    />

    <project name="qi/libqi.git"
        path="lib/libqi"
    />
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest.git", "default.xml", xml)
        worktree = qisys.worktree.create(self.tmp)
        fetched_manifest = qisrc.sync.fetch_manifest(worktree, manifest_url)
        with open(fetched_manifest, "r") as fp:
            fetched_xml = fp.read()
        self.assertEqual(fetched_xml, xml)
        manifest = qisrc.manifest.load(fetched_manifest)
        qisrc.sync.init_worktree(worktree, manifest)
        # And do it a second time, checking that we don't get an
        # 'directory not empty' git failure
        qisrc.sync.init_worktree(worktree, manifest)
コード例 #2
0
 def test_clone_project_already_exists(self):
     bar_url = create_git_repo(self.tmp, "bar")
     baz_url = create_git_repo(self.tmp, "baz")
     qisrc.sync.clone_project(self.worktree, bar_url, src="bar")
     error = None
     try:
         qisrc.sync.clone_project(self.worktree, baz_url, src="bar")
     except Exception, e:
         error = e
コード例 #3
0
ファイル: test_clone.py プロジェクト: bithium/qibuild
def test_project_already_exists(tmpdir):
    bar_url = create_git_repo(tmpdir.strpath, "bar")
    baz_url = create_git_repo(tmpdir.strpath, "baz")
    worktree = create_worktree(tmpdir)
    clone_project(worktree, bar_url, src="bar")
    # pylint: disable-msg=E1101
    with pytest.raises(Exception) as e:
        qisrc.sync.clone_project(worktree, baz_url, src="bar")
    assert "already registered" in str(e.value)
コード例 #4
0
 def test_clone_skipping(self):
     bar_url = create_git_repo(self.tmp, "bar")
     qisrc.sync.clone_project(self.worktree, bar_url)
     self.assertEqual(self.worktree.git_projects[0].src, "bar")
     qisrc.sync.clone_project(self.worktree, bar_url, skip_if_exists=True)
     self.assertEqual(len(self.worktree.git_projects), 1)
     self.assertEqual(self.worktree.git_projects[0].src, "bar")
コード例 #5
0
 def test_clone_path_already_exists(self):
     bar_url = create_git_repo(self.tmp, "bar")
     conflicting_path = os.path.join(self.worktree.root, "bar")
     qibuild.sh.mkdir(conflicting_path)
     error = None
     try:
         qisrc.sync.clone_project(self.worktree, bar_url)
     except Exception, e:
         error = e
コード例 #6
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_git_manifest_sync_branch(self):
        # Two branches in the manifest repo:
        #  - master:  3 projects: naoqi, libnaoqi and doc
        #  - release-1.12: 2 projects: naoqi and doc, but doc stays with the
        #   'master' branch
        manifest_url = create_git_repo(self.tmp, "manifest.git", with_release_branch=True)
        create_git_repo(self.tmp, "naoqi", with_release_branch=True)
        create_git_repo(self.tmp, "libnaoqi")
        create_git_repo(self.tmp, "doc")
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="naoqi.git" path="naoqi" />
    <project name="libnaoqi.git" path="lib/libnaoqi" />
    <project name="doc" path="doc" />
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest.git", "default.xml", xml)

        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" revision="release-1.12" />
    <project name="naoqi.git" path="naoqi" />
    <project name="doc" path="doc" revision="master" />
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest.git", "default.xml", xml, branch="release-1.12")

        master_root  = os.path.join(self.tmp, "work", "master")
        release_root = os.path.join(self.tmp, "work", "release-1.12")
        qisys.sh.mkdir(master_root,  recursive=True)
        qisys.sh.mkdir(release_root, recursive=True)
        master_wt  = qisys.worktree.create(master_root)
        release_wt = qisys.worktree.create(release_root)
        master_manifest = qisrc.sync.fetch_load_manifest(master_wt,  manifest_url,
            branch="master")
        release_manifest = qisrc.sync.fetch_load_manifest(release_wt, manifest_url,
            branch="release-1.12")

        qisrc.sync.init_worktree(master_wt,  master_manifest)
        qisrc.sync.init_worktree(release_wt, release_manifest)
        release_srcs = [p.src for p in release_wt.projects]
        self.assertEqual(release_srcs, ["doc", "manifest/default", "naoqi"])
        naoqi_release = release_wt.get_project("naoqi")
        readme = read_readme(naoqi_release.path)
        self.assertEqual(readme, "naoqi on release-1.12\n")
        self.assertEqual(naoqi_release.remote, "origin")
        self.assertEqual(naoqi_release.branch, "release-1.12")

        master_srcs = [p.src for p in master_wt.projects]
        self.assertEqual(master_srcs, ["doc", "lib/libnaoqi", "manifest/default", "naoqi"])
        naoqi_master = master_wt.get_project("naoqi")
        readme = read_readme(naoqi_master.path)
        self.assertEqual(readme, "naoqi\n")
        self.assertEqual(naoqi_master.remote, "origin")
        self.assertEqual(naoqi_master.branch, "master")
コード例 #7
0
    def test_sync_two_remotes(self):
        create_git_repo(self.tmp, "a/a_project.git")
        create_git_repo(self.tmp, "b/b_project.git")
        remote_a = os.path.join(self.tmp, "srv", "a")
        remote_b = os.path.join(self.tmp, "srv", "b")
        xml = """
<manifest>
    <remote name="a" fetch="{remote_a}" />
    <remote name="b" fetch="{remote_b}" />
    <project name="a_project.git" remote="a" />
    <project name="b_project.git" remote="b" />
</manifest>
"""
        xml = xml.format(remote_a=remote_a, remote_b=remote_b)
        manifest = os.path.join(self.tmp, "manifest.xml")
        with open(manifest, "w") as fp:
            fp.write(xml)
        worktree = qisrc.worktree.create(self.tmp)
        qisrc.sync.init_worktree(worktree, manifest)
コード例 #8
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_git_exists_but_not_registered(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        bar_url = create_git_repo(self.tmp, "bar")
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="bar.git" path="bar"/>
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)
        work = os.path.join(self.tmp, "work")
        worktree = qisys.worktree.create(work)
        bar_src = os.path.join(work, "bar")
        bar_git = qisrc.git.Git(bar_src)
        bar_git.clone(bar_url)
        manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url)
        qisrc.sync.init_worktree(worktree, manifest)
        bar_proj = worktree.get_project("bar")
コード例 #9
0
ファイル: test_clone.py プロジェクト: bithium/qibuild
def test_path_already_exists(tmpdir):
    bar_url = create_git_repo(tmpdir.strpath, "bar")
    worktree = create_worktree(tmpdir)
    tmpdir.join("work").mkdir("bar")
    # pylint: disable-msg=E1101
    with pytest.raises(Exception) as e:
        clone_project(worktree, bar_url)
    assert "already exists" in str(e.value)
    clone_project(worktree, bar_url, src="baz")
    assert worktree.git_projects[0].src == "baz"
コード例 #10
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_nested_git_projs(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        create_git_repo(self.tmp, "bar")
        create_git_repo(self.tmp, "foo")
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="bar.git" path="bar" />
    <project name="foo.git" path="bar/foo"/>
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)

        worktree = qisys.worktree.create(self.tmp)
        manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url)
        qisrc.sync.init_worktree(worktree, manifest)
        worktree.set_manifest_project("manifest/default")
        self.assertEqual(worktree.git_projects[0].src, "bar")
        self.assertEqual(worktree.git_projects[1].src, "bar/foo")
コード例 #11
0
def test_fetch_manifest_no_default(tmpdir):
    tmpdir = tmpdir.strpath
    manifest_url = create_git_repo(tmpdir, "manifest")

    worktree = create_worktree(tmpdir)

    # pylint: disable-msg=E1101
    with pytest.raises(Exception) as e:
        qisrc.sync.fetch_manifest(worktree, manifest_url)

    assert "Could not find a file named 'default.xml'" in str(e)
コード例 #12
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_path_exists_but_not_a_git_repo(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        bar_url = create_git_repo(self.tmp, "bar")
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="bar.git" path="bar"/>
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)
        work = os.path.join(self.tmp, "work")
        worktree = qisys.worktree.create(work)
        bar_src = os.path.join(work, "bar")
        os.mkdir(bar_src)
        manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url)
        # pylint: disable-msg=E1101
        with pytest.raises(Exception) as e:
            qisrc.sync.init_worktree(worktree, manifest)
        assert "already exists" in e.value.message
        assert "not a git repository" in e.value.message
コード例 #13
0
    def test_local_manifest_sync(self):
        create_git_repo(self.tmp, "qi/libqi")
        worktree = qisrc.worktree.create(self.tmp)
        xml = """
<manifest>
    <remote name="origin"
        fetch="{tmp}"
    />

    <project name="srv/qi/libqi.git"
        path="lib/libqi"
    />
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        manifest = StringIO(xml)
        qisrc.sync.init_worktree(worktree, manifest)
        self.assertEqual(len(worktree.projects), 1)
        libqi = worktree.projects[0]
        self.assertEqual(libqi.path,
                         os.path.join(worktree.root, "lib/libqi"))
コード例 #14
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_git_exists_but_wrong_remote(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        bar_url = create_git_repo(self.tmp, "bar")
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="bar.git" path="bar"/>
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)
        work = os.path.join(self.tmp, "work")
        worktree = qisys.worktree.create(work)
        bar_src = os.path.join(work, "bar")
        os.mkdir(bar_src)
        bar_git = qisrc.git.Git(bar_src)
        bar_git.init()
        bar_git.set_config("remote.origin.url", "git@foo/foo.git")
        manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url)
        qisrc.sync.init_worktree(worktree, manifest)
        bar_proj = worktree.get_project("bar")
        assert bar_git.get_config("remote.origin.url") == bar_url
コード例 #15
0
ファイル: test_review.py プロジェクト: bithium/qibuild
def test_push(tmpdir):
    foo_url = create_git_repo(tmpdir.strpath, "foo")
    work = tmpdir.mkdir("work")
    foo_src = work.mkdir("foo")
    foo_src = foo_src.strpath
    git = qisrc.git.Git(foo_src)
    git.clone(foo_url)

    # this should work:
    qisrc.review.push(foo_src, "master")
    (retcode, out) = git.call("ls-remote", "origin", raises=False)
    assert retcode == 0
    assert "refs/for/master" not in out
    assert "refs/heads/master" in out

    gerrit_url = create_git_repo(tmpdir.strpath, "foo-gerrit")
    git.call("remote", "add", "gerrit", gerrit_url)
    git.set_config("review.remote", "gerrit")
    git.checkout("-b", "next")
    qisrc.review.push(foo_src, "next")
    (retcode, out) = git.call("ls-remote", "gerrit", raises=False)
    assert retcode == 0
    assert "refs/for/next" in out
    assert "refs/heads/next" not in out
コード例 #16
0
def test_fetch_manifest(tmpdir):
    tmpdir = tmpdir.strpath
    manifest_url = create_git_repo(tmpdir, "manifest")
    xml = """
<manifest>
<remote fetch="git@foo" name="origin" revision="release-1.12" />
</manifest>
"""
    push_file(tmpdir, "manifest", "default.xml", xml)

    worktree = create_worktree(tmpdir)
    qisrc.sync.fetch_manifest(worktree, manifest_url)

    manifest_proj = worktree.get_project("manifest/default")
    manifest_xml = os.path.join(manifest_proj.path, "default.xml")
    with open(manifest_xml, "r") as fp:
        assert fp.read() == xml
コード例 #17
0
    def test_broken_submodules(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        create_broken_submodules(self.tmp)
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="foo.git" path="foo" />
    <project name="bar.git" path="foo/bar"/>
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)
        work = os.path.join(self.tmp, "work")
        worktree = qisrc.worktree.create(work)
        manifest = qisrc.sync.fetch_manifest(worktree, manifest_url)
        qisrc.sync.init_worktree(worktree, manifest)
        self.assertEqual(len(worktree.git_projects), 3)
コード例 #18
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_broken_submodules(self):
        manifest_url = create_git_repo(self.tmp, "manifest")
        create_broken_submodules(self.tmp)
        xml = """
<manifest>
    <remote name="origin" fetch="{tmp}/srv" />
    <project name="foo.git" path="foo" />
</manifest>
"""
        xml = xml.format(tmp=self.tmp)
        push_file(self.tmp, "manifest", "default.xml", xml)
        work = os.path.join(self.tmp, "work")
        worktree = qisys.worktree.create(work)
        manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url)
        # pylint: disable-msg=E1101
        with pytest.raises(Exception) as e:
            qisrc.sync.init_worktree(worktree, manifest)
        assert "Broken submodules" in str(e.value)
コード例 #19
0
ファイル: test_sync.py プロジェクト: bithium/qibuild
    def test_manifest_wrong_revision(self):
        manifest_url = create_git_repo(self.tmp, "manifest", with_release_branch=True)
        xml = """
<manifest>
    <remote fetch="git@foo" name="origin" revision="release-1.12" />
</manifest>
"""
        push_file(self.tmp, "manifest", "default.xml", xml, branch="release-1.12")
        worktree = qisys.worktree.create(self.tmp)
        qisrc.sync.clone_project(worktree, manifest_url)
        fetched_manifest = qisrc.sync.fetch_load_manifest(worktree, manifest_url, branch="release-1.12")
        qisrc.sync.init_worktree(worktree, fetched_manifest)
        worktree.set_manifest_project("manifest/default")
        manifest_projects = worktree.get_manifest_projects()
        self.assertEqual(len(manifest_projects), 1)
        manifest_path = manifest_projects[0].path
        readme = read_readme(manifest_path)
        self.assertEqual(readme, "manifest on release-1.12\n")
コード例 #20
0
def test_fetch_manifest_custom_profile(tmpdir):
    tmpdir = tmpdir.strpath
    manifest_url = create_git_repo(tmpdir, "manifest")
    xml = """
<manifest>
    <project name="doc/doc.git" src="doc/general" />
    <project name="doc/internal.git" src="doc/internal" />
</manifest>
"""

    push_file(tmpdir, "manifest", "internal.xml", xml)

    worktree = create_worktree(tmpdir)
    qisrc.sync.fetch_manifest(worktree, manifest_url, profile="internal")

    manifest_proj = worktree.get_project("manifest/default")
    manifest_xml = os.path.join(manifest_proj.path, "internal.xml")
    with open(manifest_xml, "r") as fp:
        assert fp.read() == xml
コード例 #21
0
ファイル: test_clone.py プロジェクト: bithium/qibuild
def test_simple(tmpdir):
    bar_url = create_git_repo(tmpdir.strpath, "bar")
    worktree = create_worktree(tmpdir)
    clone_project(worktree, bar_url)
    assert len(worktree.git_projects) == 1
    assert worktree.git_projects[0].src == "bar"
コード例 #22
0
 def test_simple_clone(self):
     bar_url = create_git_repo(self.tmp, "bar")
     qisrc.sync.clone_project(self.worktree, bar_url)
     self.assertEqual(self.worktree.git_projects[0].src, "bar")