Пример #1
0
 def _clone_missing(self, git_project, repo):
     """ Clone Missing """
     branch = repo.default_branch
     fixed_ref = repo.fixed_ref
     clone_url = repo.clone_url
     qisys.sh.mkdir(git_project.path, recursive=True)
     git = qisrc.git.Git(git_project.path)
     remote_name = repo.default_remote.name
     try:
         git.init()
         git.remote("add", remote_name, clone_url)
         git.fetch(remote_name, "--quiet")
         if branch:
             git.checkout("-b", branch, "%s/%s" % (remote_name, branch))
         if fixed_ref:
             git.checkout("-q", fixed_ref)
     except Exception:
         ui.error("Cloning repo failed")
         if git.is_empty():
             qisys.sh.rm(git_project.path)
         self.worktree.remove_project(repo.src)
         return False
     self.save_project_config(git_project)
     self.load_git_projects()
     return True
Пример #2
0
    def _create_repo(self, project, src=None, review=False, empty=False):
        """ Helper for self.create_repo """
        if not src:
            src = project.replace(".git", "")

        if review:
            repo_srv = self.gerrit.ensure(project, dir=True)
        else:
            repo_srv = self.srv.ensure(project, dir=True)

        repo_url = "file://" + qisys.sh.to_posix_path(repo_srv.strpath)
        git = qisrc.git.Git(repo_srv.strpath)
        git.init("--bare")

        repo_src = self.src.ensure(src, dir=True)
        git = TestGit(repo_src.strpath)
        git.initialize()
        if review:
            remote_name = "gerrit"
        else:
            remote_name = "origin"

        git.set_remote(remote_name, repo_url)
        if not empty:
            git.push(remote_name, "master:master")
        return repo_src.strpath
Пример #3
0
 def _import_manifest(self, import_manifest=None):
     """ Import Manifest """
     if import_manifest.project is None:
         return
     repo_name = os.path.split(import_manifest.project)[1].replace(
         ".git", "")
     repo = os.path.join(self.git_worktree.root, ".qi", "manifests",
                         repo_name)
     import_manifest.repo = repo
     if not os.path.exists(repo):
         qisys.sh.mkdir(repo, recursive=True)
         git = qisrc.git.Git(repo)
         git.init()
         manifest_xml = os.path.join(repo, "manifest.xml")
         with open(manifest_xml, "w") as fp:
             fp.write("<manifest />")
         git.add(".")
         git.commit("-m", "initial commit")
     if import_manifest.branch:
         import_manifest.default_branch = import_manifest.branch
     else:
         import_manifest.default_branch = self.manifest.branch
     self._sync_git(repo, import_manifest.remotes[0].url,
                    import_manifest.default_branch,
                    import_manifest.fixed_ref)
Пример #4
0
def test_set_tracking_branch_existing_branch_tracking_other(tmpdir):
    git = qisrc.git.Git(tmpdir.strpath)
    git.init()
    git.commit("-m", "empty", "--allow-empty")
    git.set_tracking_branch("master", "origin")
    ret = git.set_tracking_branch("master", "other")
    assert ret is True
Пример #5
0
    def _create_repo(self, project, src=None, review=False, empty=False):
        """ Helper for self.create_repo """
        if not src:
            src = project.replace(".git", "")

        if review:
            repo_srv = self.gerrit.ensure(project, dir=True)
        else:
            repo_srv = self.srv.ensure(project, dir=True)

        repo_url = "file://" + qisys.sh.to_posix_path(repo_srv.strpath)
        git = qisrc.git.Git(repo_srv.strpath)
        git.init("--bare")

        repo_src = self.src.ensure(src, dir=True)
        git = TestGit(repo_src.strpath)
        git.initialize()
        if review:
            remote_name = "gerrit"
        else:
            remote_name = "origin"

        git.set_remote(remote_name, repo_url)
        if not empty:
            git.push(remote_name, "master:master")
        return repo_src.strpath
Пример #6
0
def test_is_ff(tmpdir):
    a_git = tmpdir.mkdir("a_git_project")
    a_src = a_git.strpath

    git = qisrc.git.Git(a_src)
    git.init()
    write_readme(a_src, "readme\n")
    git.add(".")
    git.commit("-m", "initial commit")
    git.call("branch", "A")

    write_readme(a_src, "readme2\n")
    git.add(".")
    git.commit("-m", "second commit")
    git.call("branch", "B")

    (ret, out) = git.call("show-ref", "--verify", "refs/heads/A", raises=False)
    A_sha1 = out.split()[0]
    (ret, out) = git.call("show-ref", "--verify", "refs/heads/B", raises=False)
    B_sha1 = out.split()[0]

    class Status:
        pass
    status = Status()
    status.mess = ""
    assert qisrc.git.is_ff(git, status, A_sha1, B_sha1) == True
    assert qisrc.git.is_ff(git, status, B_sha1, A_sha1) == False
    assert qisrc.git.is_ff(git, status, A_sha1, A_sha1) == True
Пример #7
0
def test_set_tracking_branch_existing_branch_tracking_none(tmpdir):
    """ Test Set Tracking Branch Existing Branch Tracking None """
    git = qisrc.git.Git(tmpdir.strpath)
    git.init()
    git.commit("-m", "empty", "--allow-empty")
    ret = git.set_tracking_branch("master", "master", "origin")
    assert ret is True
Пример #8
0
def test_get_ref_sha1(tmpdir):
    a_git = tmpdir.mkdir("a_git_project")
    git = qisrc.git.Git(a_git.strpath)

    assert git.is_valid() == False

    git.init()
    assert git.is_valid() == True
Пример #9
0
def test_relative_path(qisrc_action, tmpdir):
    git = qisrc.git.Git(tmpdir.strpath)
    git.init()
    manifest = tmpdir.join("manifest.xml")
    manifest.write("<manifest />")
    git.add("manifest.xml")
    git.commit("-m", "Initial commit")
    qisrc_action("init", os.path.relpath(tmpdir.strpath))
    assert os.path.isfile(os.path.join(".qi", "manifests", "default", "manifest.xml"))
Пример #10
0
def test_relative_path(qisrc_action, tmpdir):
    git = qisrc.git.Git(tmpdir.strpath)
    git.init()
    manifest = tmpdir.join("manifest.xml")
    manifest.write("<manifest />")
    git.add("manifest.xml")
    git.commit("-m", "Initial commit")
    qisrc_action("init", os.path.relpath(tmpdir.strpath))
    assert os.path.isfile(
        os.path.join(".qi", "manifests", "default", "manifest.xml"))
Пример #11
0
def test_create_in_git_dir(tmpdir):
    a_git = tmpdir.mkdir("a_git_project")
    a_manifest = tmpdir.join("a_manifest.xml")
    a_manifest.write("<manifest />")
    git = qisrc.git.Git(a_git.strpath)
    git.init()
    work = a_git.mkdir("work")
    # pylint: disable-msg=E1101
    with pytest.raises(Exception) as e:
        qisys.worktree.create(work.strpath)
    assert "inside a git project" in e.value.message
Пример #12
0
def test_get_repo_root(tmpdir):
    a_nogit = tmpdir.mkdir("a_nogit_project")
    a_git = tmpdir.mkdir("a_git_project")
    git = qisrc.git.Git(a_git.strpath)
    git.init()
    work = a_git.mkdir("work")

    assert qisrc.git.get_repo_root(a_nogit.strpath) == None
    assert qisrc.git.get_repo_root(a_git.strpath)   == a_git.strpath
    assert qisrc.git.get_repo_root(work.strpath)    == a_git.strpath
    assert qisrc.git.get_repo_root(os.path.join(tmpdir.strpath, "pouet")) == None
Пример #13
0
 def manifest_repo(self):
     # the repo is always in manifests/default for backward-compatible reasons
     res = os.path.join(self.git_worktree.root, ".qi", "manifests", "default")
     if not os.path.exists(res):
         qisys.sh.mkdir(res, recursive=True)
         git = qisrc.git.Git(res)
         git.init()
         manifest_xml = os.path.join(res, "manifest.xml")
         with open(manifest_xml, "w") as fp:
             fp.write("<manifest />")
         git.add(".")
         git.commit("-m", "initial commit")
     return res
Пример #14
0
 def manifest_repo(self):
     # the repo is always in manifests/default for backward-compatible reasons
     res = os.path.join(self.git_worktree.root, ".qi", "manifests", "default")
     if not os.path.exists(res):
         qisys.sh.mkdir(res, recursive=True)
         git = qisrc.git.Git(res)
         git.init()
         manifest_xml = os.path.join(res, "manifest.xml")
         with open(manifest_xml, "w") as fp:
             fp.write("<manifest />")
         git.add(".")
         git.commit("-m", "initial commit")
     return res
Пример #15
0
def test_no_duplicate_deps(cd_to_tmpdir, args):
    args.dep_types = "default"
    build_worktree = TestBuildWorkTree()
    foo = build_worktree.create_project("foo", run_depends=["bar"])
    build_worktree.create_project("bar", src="foo/bar")
    git = qisrc.git.Git(foo.path)
    git.init()
    git_worktree = TestGitWorkTree()

    with qisys.sh.change_cwd(cd_to_tmpdir.join("foo").strpath):
        projs = get_git_projects(git_worktree, args, default_all=True,
                                 use_build_deps=True)
    assert projs == [foo]
Пример #16
0
def test_no_duplicate_deps(cd_to_tmpdir, args):
    args.dep_types = "default"
    build_worktree = TestBuildWorkTree()
    foo = build_worktree.create_project("foo", run_depends=["bar"])
    build_worktree.create_project("bar", src="foo/bar")
    git = qisrc.git.Git(foo.path)
    git.init()
    git_worktree = TestGitWorkTree()

    with qisys.sh.change_cwd(cd_to_tmpdir.join("foo").strpath):
        projs = get_git_projects(git_worktree, args, default_all=True,
                                 use_build_deps=True)
    assert projs == [foo]
Пример #17
0
def test_gen_scm_info(build_worktree, tmpdir):
    build_worktree.add_test_project("world")
    hello_proj = build_worktree.add_test_project("hello")
    git = qisrc.git.Git(hello_proj.path)
    git.init()
    git.add(".")
    git.commit("--message", "initial commit")
    rc, sha1 = git.call("rev-parse", "HEAD", raises=False)
    package_xml = tmpdir.join("package.xml").strpath
    hello_proj.gen_package_xml(package_xml)
    tree = qisys.qixml.read(package_xml)
    scm_elem = tree.find("scm")
    git_elem = scm_elem.find("git")
    assert git_elem.get("revision") == sha1
Пример #18
0
def test_gen_scm_info(build_worktree, tmpdir):
    build_worktree.add_test_project("world")
    hello_proj = build_worktree.add_test_project("hello")
    git = qisrc.git.Git(hello_proj.path)
    git.init()
    git.add(".")
    git.commit("--message", "initial commit")
    rc, sha1 = git.call("rev-parse", "HEAD", raises=False)
    package_xml = tmpdir.join("package.xml").strpath
    hello_proj.gen_package_xml(package_xml)
    tree = qisys.qixml.read(package_xml)
    scm_elem = tree.find("scm")
    git_elem = scm_elem.find("git")
    assert git_elem.get("revision") == sha1
Пример #19
0
def test_guess_git_repo(tmpdir, args):
    worktree = qisys.worktree.WorkTree(tmpdir.strpath)
    foo = tmpdir.mkdir("foo")
    bar = foo.mkdir("bar")
    foo.join("qiproject.xml").write("""<project>
  <project src="bar" />
</project>
""")
    worktree.add_project("foo")
    git = qisrc.git.Git(foo.strpath)
    git.init()
    git_worktree = qisrc.worktree.GitWorkTree(worktree)

    with qisys.sh.change_cwd(bar.strpath):
        assert qisys.parsers.get_projects(worktree, args)[0].src == "foo/bar"
        assert get_git_projects(git_worktree, args)[0].src == "foo"
Пример #20
0
def test_build_deps_not_top_dir(cd_to_tmpdir, args):
    args.dep_types = "default"
    build_worktree = TestBuildWorkTree()
    dep_proj = build_worktree.create_project("dep")
    git = qisrc.git.Git(dep_proj.path)
    git.init()
    foo = build_worktree.create_project("foo", src="top/foo", build_depends=["dep"])
    top_proj = build_worktree.worktree.add_project("top")
    git = qisrc.git.Git(top_proj.path)
    git.init()
    git_worktree = TestGitWorkTree()
    top_proj = git_worktree.get_git_project("top")
    dep_proj = git_worktree.get_git_project("dep")
    with qisys.sh.change_cwd(cd_to_tmpdir.join("top", "foo").strpath):
        projs =  get_git_projects(git_worktree, args,
                                  use_build_deps=True)
        assert projs == [dep_proj, top_proj]
Пример #21
0
def test_build_deps_not_top_dir(cd_to_tmpdir, args):
    args.dep_types = "default"
    build_worktree = TestBuildWorkTree()
    dep_proj = build_worktree.create_project("dep")
    git = qisrc.git.Git(dep_proj.path)
    git.init()
    foo = build_worktree.create_project("foo", src="top/foo", build_depends=["dep"])
    top_proj = build_worktree.worktree.add_project("top")
    git = qisrc.git.Git(top_proj.path)
    git.init()
    git_worktree = TestGitWorkTree()
    top_proj = git_worktree.get_git_project("top")
    dep_proj = git_worktree.get_git_project("dep")
    with qisys.sh.change_cwd(cd_to_tmpdir.join("top", "foo").strpath):
        projs =  get_git_projects(git_worktree, args,
                                  use_build_deps=True)
        assert projs == [dep_proj, top_proj]
Пример #22
0
 def _clone_missing(self, git_project, repo):
     branch = repo.default_branch
     clone_url = repo.clone_url
     qisys.sh.mkdir(git_project.path, recursive=True)
     git = qisrc.git.Git(git_project.path)
     remote_name = repo.default_remote.name
     try:
         git.init()
         git.remote("add", remote_name, clone_url)
         git.fetch(remote_name, "--quiet")
         git.checkout("-b", branch, "%s/%s" % (remote_name, branch))
     except:
         ui.error("Cloning repo failed")
         if git.is_empty():
             qisys.sh.rm(git_project.path)
         self.worktree.remove_project(repo.src)
         return False
     self.save_project_config(git_project)
     self.load_git_projects()
     return True
Пример #23
0
 def _clone_missing(self, git_project, repo):
     branch = repo.default_branch
     clone_url = repo.clone_url
     qisys.sh.mkdir(git_project.path, recursive=True)
     git = qisrc.git.Git(git_project.path)
     remote_name = repo.default_remote.name
     try:
         git.init()
         git.remote("add", remote_name, clone_url)
         git.fetch(remote_name, "--quiet")
         remote_branch = "%s/%s" % (remote_name, branch)
         rc, _ = git.call("rev-parse", "--verify", "--quiet", remote_branch, raises=False)
         # When `remote_branch` is invalid, try to checkout `branch` instead
         git.checkout("-b", branch, branch if rc else remote_branch)
     except:
         ui.error("Cloning repo failed")
         if git.is_empty():
             qisys.sh.rm(git_project.path)
         self.worktree.remove_project(repo.src)
         return False
     self.save_project_config(git_project)
     self.load_git_projects()
     return True
Пример #24
0
 def _clone_missing(self, git_project, repo):
     branch = repo.default_branch
     clone_url = repo.clone_url
     qisys.sh.mkdir(git_project.path, recursive=True)
     git = qisrc.git.Git(git_project.path)
     remote_name = repo.default_remote.name
     try:
         git.init()
         git.remote("add", remote_name, clone_url)
         git.fetch(remote_name, "--quiet")
         remote_branch = "%s/%s" % (remote_name, branch)
         rc, _ = git.call("rev-parse", "--verify", "--quiet", remote_branch, raises=False)
         # When `remote_branch` is invalid, try to checkout `branch` instead
         git.checkout("-b", branch, branch if rc else remote_branch)
     except:
         ui.error("Cloning repo failed")
         if git.is_empty():
             qisys.sh.rm(git_project.path)
         self.worktree.remove_project(repo.src)
         return False
     self.save_project_config(git_project)
     self.load_git_projects()
     return True
Пример #25
0
def setup_test():
    build_worktree = TestBuildWorkTree()
    foo = build_worktree.create_project("foo")
    world = build_worktree.create_project("world")
    hello = build_worktree.create_project("hello", build_depends=["world"])
    git = qisrc.git.Git(foo.path)
    git.init()
    git = qisrc.git.Git(world.path)
    git.init()
    git = qisrc.git.Git(hello.path)
    git.init()
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    hello = git_worktree.get_git_project("hello")
    world = git_worktree.get_git_project("world")
    return (foo, hello, world)
Пример #26
0
def setup_test():
    build_worktree = TestBuildWorkTree()
    foo = build_worktree.create_project("foo")
    world = build_worktree.create_project("world")
    hello = build_worktree.create_project("hello", build_depends=["world"])
    git = qisrc.git.Git(foo.path)
    git.init()
    git = qisrc.git.Git(world.path)
    git.init()
    git = qisrc.git.Git(hello.path)
    git.init()
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    hello = git_worktree.get_git_project("hello")
    world = git_worktree.get_git_project("world")
    return (foo, hello, world)
Пример #27
0
def test_set_tracking_branch_on_empty_repo(tmpdir):
    git = qisrc.git.Git(tmpdir.strpath)
    git.init()
    ret = git.set_tracking_branch("master", "master", "origin")
    assert ret is False