Exemplo n.º 1
0
    def push_file(self, project, filename, contents,
                  branch="master", fast_forward=True,
                  message=None):
        """ Push a new file with the given contents to the given project
        It is assumed that the project has been created

        """
        src = project.replace(".git", "")
        repo_src = self.src.join(src)
        git = qisrc.git.Git(repo_src.strpath)
        if git.get_current_branch() != branch:
            git.checkout("--force", "-B", branch)
        if not fast_forward:
            git.reset("--hard", "HEAD~1")
        to_write = repo_src.join(filename)
        if not message:
            if to_write.check(file=True):
                message = "Update %s" % filename
            else:
                message = "Add %s" % filename
        repo_src.ensure(filename, file=True)
        repo_src.join(filename).write(contents)
        git.add(filename)
        git.commit("--message", message)
        if fast_forward:
            git.push("origin", "%s:%s" % (branch, branch))
        else:
            git.push("origin", "--force", "%s:%s" % (branch, branch))
Exemplo n.º 2
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
Exemplo n.º 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)
Exemplo n.º 4
0
    def push_file(self, project, filename, contents,
                  branch="master", fast_forward=True,
                  message=None):
        """ Push a new file with the given contents to the given project
        It is assumed that the project has beed created

        """
        src = project.replace(".git", "")
        repo_src = self.src.join(src)
        git = qisrc.git.Git(repo_src.strpath)
        if git.get_current_branch() != branch:
            git.checkout("--force", "-B", branch)
        if not fast_forward:
            git.reset("--hard", "HEAD~1")
        to_write = repo_src.join(filename)
        if not message:
            if to_write.check(file=True):
                message = "Update %s" % filename
            else:
                message = "Add %s" % filename
        repo_src.ensure(filename, file=True)
        repo_src.join(filename).write(contents)
        git.add(filename)
        git.commit("--message", message)
        if fast_forward:
            git.push("origin", "%s:%s" % (branch, branch))
        else:
            git.push("origin", "--force", "%s:%s" % (branch, branch))
Exemplo n.º 5
0
    def test_conflict(self):
        bar_url = create_git_repo(self.tmp, "bar")
        work = os.path.join(self.tmp, "work")
        qibuild.sh.mkdir(work)
        bar_src = os.path.join(work, "bar")
        git = qisrc.git.Git(bar_src)
        git.clone(bar_url)

        # Create conflicting changes
        write_readme(bar_src, "conflicting changes\n", append=True)
        git.commit("-a", "-m", "conflicting changes")
        push_readme_v2(self.tmp, "bar", "master")

        # Updating branch should fail
        err = git.update_branch("master", "origin")
        self.assertTrue(err)
        self.assertTrue("Merge conflict in README" in err, err)

        # But we should be back at our previous commit
        readme = read_readme(bar_src)
        self.assertEqual(readme, "bar\nconflicting changes\n")

        self.assertEqual(git.get_current_branch(), "master")
        rebase_apply = os.path.join(git.repo, ".git", "rebase_apply")
        self.assertFalse(os.path.exists(rebase_apply))
Exemplo n.º 6
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
Exemplo n.º 7
0
    def push_submodule(self, project, submodule_url, destination_dir,
                       branch="master", fast_forward=True,
                       message=None):
        """
        Push a submodule to the given project.
        It is assumed that the project has been created.
        """
        src = project.replace(".git", "")
        repo_src = self.src.join(src)
        git = qisrc.git.Git(repo_src.strpath)
        if git.get_current_branch() != branch:
            git.checkout("--force", "-B", branch)
        if not fast_forward:
            git.reset("--hard", "HEAD~1")

        to_write = repo_src.join(destination_dir)
        if to_write.exists():
            raise RuntimeError("path %s already exists" % destination_dir)

        if not message:
            message = "Add submodule %s" % destination_dir

        git.call("submodule", "add", submodule_url, destination_dir)
        git.add(destination_dir)
        git.commit("--message", message)
        if fast_forward:
            git.push("origin", "%s:%s" % (branch, branch))
        else:
            git.push("origin", "--force", "%s:%s" % (branch, branch))
Exemplo n.º 8
0
    def test_wrong_branch(self):
        bar_url = create_git_repo(self.tmp, "bar")
        work = os.path.join(self.tmp, "work")
        qibuild.sh.mkdir(work)
        bar_src = os.path.join(work, "bar")
        git = qisrc.git.Git(bar_src)
        git.clone(bar_url)
        git.update_branch("master", "origin")
        readme = read_readme(bar_src)
        self.assertEqual(readme, "bar\n")

        # Checkout a 'next' branch
        git.checkout("-b", "next")
        with open(os.path.join(bar_src, "README"), "w") as fp:
            fp.write("bar on next\n")
        git.commit("-a", "-m", "README next")

        # Push a new commit
        push_readme_v2(self.tmp, "bar", "master")

        # Update, check that master is up to date
        err = git.update_branch("master", "origin")
        self.assertFalse(err)
        git.checkout("master")
        readme = read_readme(bar_src)
        self.assertEqual(readme, "bar v2 on master\n")
Exemplo n.º 9
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
Exemplo n.º 10
0
 def delete_file(self, project, filename):
     """ Delete a file from the repository """
     src = project.replace(".git", "")
     repo_src = self.src.join(src)
     git = qisrc.git.Git(repo_src.strpath)
     git.call("rm", filename)
     git.commit("--message", "remove %s" % filename)
     git.push("origin", "master:master")
Exemplo n.º 11
0
 def delete_file(self, project, filename):
     """ Delete a file from the repository """
     src = project.replace(".git", "")
     repo_src = self.src.join(src)
     git = qisrc.git.Git(repo_src.strpath)
     git.call("rm", filename)
     git.commit("--message", "remove %s" % filename)
     git.push("origin", "master:master")
Exemplo n.º 12
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"))
Exemplo n.º 13
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"))
Exemplo n.º 14
0
 def push_manifest(self, message, allow_empty=False):
     """ Push new manifest.xml version """
     manifest_repo = self.root.join("src", "manifest")
     git = qisrc.git.Git(manifest_repo.strpath)
     commit_args = ["--all", "--message", message]
     if allow_empty:
         commit_args.append("--allow-empty")
     git.commit(*commit_args)
     git.checkout("--force", "-B", self.manifest_branch)
     git.push("origin", "%s:%s" % (self.manifest_branch, self.manifest_branch))
Exemplo n.º 15
0
 def push_manifest(self, message, allow_empty=False):
     """ Push new manifest.xml version """
     manifest_repo = self.root.join("src", "manifest")
     git = qisrc.git.Git(manifest_repo.strpath)
     commit_args = ["--all", "--message", message]
     if allow_empty:
         commit_args.append("--allow-empty")
     git.commit(*commit_args)
     if git.get_current_branch() != self.manifest_branch:
         git.checkout("--force", "-B", self.manifest_branch)
     git.push("origin", "%s:%s" % (self.manifest_branch, self.manifest_branch))
Exemplo n.º 16
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
Exemplo n.º 17
0
 def add_qibuild_test_project(self, src):
     project_name = src + ".git"
     repo_src = self._create_repo(project_name , src=src, review=False)
     this_dir = os.path.dirname(__file__)
     src_path = os.path.join(this_dir, "..", "..", "qibuild", "test", "projects", src)
     qisys.sh.copy_git_src(src_path, repo_src)
     git = TestGit(repo_src)
     git.add(".")
     git.commit("--message", "Add sources from qibuild test project %s" % src)
     git.push("origin", "master:master")
     self.manifest.add_repo(project_name, src, ["origin"])
     repo = self.manifest.get_repo(project_name)
     self.push_manifest("Add qibuild test project: %s" % src)
Exemplo n.º 18
0
 def add_qibuild_test_project(self, src):
     project_name = src + ".git"
     repo_src = self._create_repo(project_name, src=src, review=False)
     this_dir = os.path.dirname(__file__)
     src_path = os.path.join(this_dir, "..", "..", "qibuild", "test", "projects", src)
     qisys.sh.copy_git_src(src_path, repo_src)
     git = TestGit(repo_src)
     git.add(".")
     git.commit("--message", "Add sources from qibuild test project %s" % src)
     git.push("origin", "master:master")
     self.manifest.add_repo(project_name, src, ["origin"])
     repo = self.manifest.get_repo(project_name)
     self.push_manifest("Add qibuild test project: %s" % src)
Exemplo n.º 19
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
Exemplo n.º 20
0
def test_git_get_local_branches(tmpdir):
    tmpdir = tmpdir.strpath
    git = qisrc.git.Git(tmpdir)
    # pylint: disable-msg=E1101
    with pytest.raises(Exception):
        git.get_local_branches()
    write_readme(tmpdir, "readme\n")
    git.call("init")
    git.call("add", ".")
    git.commit("-m", "initial commit")
    assert git.get_local_branches() == ["master"]
    git.checkout("-b", "devel")
    assert git.get_local_branches() == ["devel", "master"]
Exemplo n.º 21
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
Exemplo n.º 22
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
Exemplo n.º 23
0
def push_file(tmp, git_path, filename, contents, branch="master"):
    """ Push a file to the given url. Assumes the repository
    has been created with :py:func:`create_git_repo` with the same
    path

    """
    tmp_src = os.path.join(tmp, "src", git_path)
    tmp_srv = os.path.join(tmp, "srv", git_path + ".git")
    git = qisrc.git.Git(tmp_src)
    if branch in git.get_local_branches():
        git.checkout("-f", branch)
    else:
        git.checkout("-b", branch)
    dirname = os.path.dirname(filename)
    qibuild.sh.mkdir(os.path.join(tmp_src, dirname), recursive=True)
    with open(os.path.join(tmp_src, filename), "w") as fp:
        fp.write(contents)
    git.add(filename)
    git.commit("-m", "added %s" % filename)
    git.push(tmp_srv, "%s:%s" % (branch, branch))
Exemplo n.º 24
0
    def test_wrong_branch_with_conflicts(self):
        bar_url = create_git_repo(self.tmp, "bar")
        work = os.path.join(self.tmp, "work")
        qibuild.sh.mkdir(work)
        bar_src = os.path.join(work, "bar")
        git = qisrc.git.Git(bar_src)
        git.clone(bar_url)

        # Create conflicting changes
        write_readme(bar_src, "conflicting changes\n", append=True)
        git.commit("-a", "-m", "conflicting changes")
        push_readme_v2(self.tmp, "bar", "master")

        # Checkout an other branch
        git.checkout("-b", "next")

        # Try to update master while being on an other branch:
        err = git.update_branch("master", "origin")
        self.assertTrue(err)
        self.assertTrue("Merge is not fast-forward" in err)
Exemplo n.º 25
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("version")
    args = parser.parse_args()
    version = args.version
    this_dir = os.path.dirname(__file__)
    qibuild_root = os.path.join(this_dir, "..")
    git = qisrc.git.Git(qibuild_root)
    ok, message = git.require_clean_worktree()
    if not ok:
        raise Exception(message)
    for filename in FILES_TO_PATCH:
        full_path = os.path.join(qibuild_root, filename)
        fix_version_for_file(full_path, "next", version)
    git.commit("--all", "-m", "qibuild %s" % version)
    git.call("tag", "v" + version)
    for filename in FILES_TO_PATCH:
        full_path = os.path.join(qibuild_root, filename)
        fix_version_for_file(filename, version, "next")
    git.commit("--all", "-m", "start next development")
    print "All OK feel free to push"
Exemplo n.º 26
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("version")
    args = parser.parse_args()
    version = args.version
    this_dir = os.path.dirname(__file__)
    qibuild_root = os.path.join(this_dir, "..")
    git = qisrc.git.Git(qibuild_root)
    ok, message = git.require_clean_worktree()
    if not ok:
        raise Exception(message)
    for filename in FILES_TO_PATCH:
        full_path = os.path.join(qibuild_root, filename)
        fix_version_for_file(full_path, "next", version)
    git.commit("--all", "-m", "qibuild %s" % version)
    git.call("tag", "v" + version)
    for filename in FILES_TO_PATCH:
        full_path = os.path.join(qibuild_root, filename)
        fix_version_for_file(filename, version, "next")
    git.commit("--all", "-m", "start next development")
    print "All OK feel free to push"