예제 #1
0
파일: review.py 프로젝트: Grimy/qibuild
def push(project,  branch, bypass_review=False, dry_run=False,
         reviewers=None, topic=None):
    """ Push the changes for review.

    Unless review is False, in this case, simply update
    the remote gerrit branch

    :param reviewers: A list of reviewers to invite to review

    """
    git = qisrc.git.Git(project.path)
    review_remote = project.review_remote
    args = list()
    if dry_run:
        args.append("--dry-run")
    args.append(review_remote.url)
    if bypass_review:
        args.append("%s:%s" % (branch, branch))
    else:
        ui.info("Pushing code to", review_remote.name, "for review.")
        remote_ref = "refs/for/%s" % branch
        if topic:
            remote_ref = "%s/%s" % (remote_ref, topic)
        args.append("%s:%s" % (branch, remote_ref))
        if reviewers:
            reviewers = guess_emails(git, reviewers)
            receive_pack = "git receive-pack"
            for reviewer in reviewers:
                receive_pack += " --reviewer=%s" % reviewer
            args = ["--receive-pack=%s" % receive_pack] + args
    git.push(*args)
예제 #2
0
파일: push.py 프로젝트: Fantomatic/qibuild
def do(args):
    """ Main entry point """
    git_worktree = qisrc.parsers.get_git_worktree(args)
    git_projects = qisrc.parsers.get_git_projects(git_worktree, args)
    for git_project in git_projects:
        maintainers = qisrc.maintainers.get(git_project)
        if not maintainers:
            mess = """\
The project in {src} has no maintainer.
Please edit {qiproject_xml} to silence this warning
"""
            ui.warning(mess.format(src=git_project.src, qiproject_xml=git_project.qiproject_xml), end="")
        reviewers = [x["email"] for x in maintainers]
        reviewers.extend(args.reviewers or list())
        git = qisrc.git.Git(git_project.path)
        current_branch = git.get_current_branch()
        if not current_branch:
            ui.error("Not currently on any branch")
            sys.exit(2)
        if git_project.review:
            qisrc.review.push(
                git_project,
                current_branch,
                bypass_review=(not args.review),
                dry_run=args.dry_run,
                reviewers=reviewers,
                topic=args.topic,
            )
        else:
            if args.dry_run:
                git.push("-n")
            else:
                git.push()
예제 #3
0
파일: review.py 프로젝트: bithium/qibuild
def push(project_path, branch, review=True, dry_run=False, reviewers=None):
    """ Push the changes for review.

    Unless review is False, in this case, simply update
    the remote gerrit branch

    :param reviewers: A list of reviewers to invite to review

    """
    git = qisrc.git.Git(project_path)
    review_remote = git.get_config("review.remote")
    args = list()
    if dry_run:
        args.append("--dry-run")
    if not review_remote:
        # Repository not configured for code review:
        # we just follow the normal 'git push' behavior
        git.push(*args)
        return
    args.append(review_remote)
    if review:
        ui.info('Pushing code to gerrit for review.')
        args.append("%s:refs/for/%s" % (branch, branch))
        if reviewers:
            reviewers = guess_emails(git, reviewers)
            receive_pack = "git receive-pack"
            for reviewer in reviewers:
                receive_pack += " --reviewer=%s" % reviewer
            args = ["--receive-pack=%s" % receive_pack] + args
    else:
        args.append("%s:%s" % (branch, branch))
    git.push(*args)
예제 #4
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))
예제 #5
0
파일: conftest.py 프로젝트: alkino/qibuild
    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
파일: conftest.py 프로젝트: alkino/qibuild
    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))
예제 #7
0
 def push_branch(self, project, branch):
     """ push branch on project """
     src = project.replace(".git", "")
     repo_src = self.src.join(src)
     git = qisrc.git.Git(repo_src.strpath)
     # create the branch
     git.call("branch", branch)
     git.push("origin", branch)
예제 #8
0
파일: conftest.py 프로젝트: alkino/qibuild
 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")
예제 #9
0
파일: conftest.py 프로젝트: Giessen/qibuild
 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))
예제 #10
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))
예제 #11
0
파일: conftest.py 프로젝트: alkino/qibuild
 def change_branch(self, project, new_branch):
     repo = self.get_repo(project)
     repo_src = self.src.join(repo.src)
     git = qisrc.git.Git(repo_src.strpath)
     git.checkout("--force", "-B", new_branch)
     for remote in repo.remotes:
         git.push(remote.url, "%s:%s" % (new_branch, new_branch))
     repo.default_branch = new_branch
     self.manifest.dump()
     self.push_manifest("%s on %s" % (repo.project, new_branch))
     self.manifest.load()
예제 #12
0
 def change_branch(self, project, new_branch):
     repo = self.get_repo(project)
     repo_src = self.src.join(repo.src)
     git = qisrc.git.Git(repo_src.strpath)
     git.checkout("--force", "-B", new_branch)
     for remote in repo.remotes:
         git.push(remote.url, "%s:%s" % (new_branch, new_branch))
     repo.default_branch = new_branch
     self.manifest.dump()
     self.push_manifest("%s on %s" % (repo.project, new_branch))
     self.manifest.load()
예제 #13
0
파일: conftest.py 프로젝트: alkino/qibuild
 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)
예제 #14
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)
예제 #15
0
def push(project,
         branch,
         bypass_review=False,
         dry_run=False,
         reviewers=None,
         topic=None):
    # pylint: disable=too-many-locals
    """ Push the changes for review.

    Unless review is False, in this case, simply update
    the remote gerrit branch

    :param reviewers: A list of reviewers to invite to review

    """
    git = qisrc.git.Git(project.path)
    review_remote = project.review_remote
    args = list()
    if dry_run:
        args.append("--dry-run")
    args.append(review_remote.url)
    if bypass_review:
        args.append("%s:%s" % (branch, branch))
    else:
        ui.info("Pushing code to", review_remote.name, "for review.")
        remote_ref = "refs/for/%s" % branch
        if topic:
            remote_ref = "%s/%s" % (remote_ref, topic)
        args.append("%s:%s" % (branch, remote_ref))
    if reviewers and not dry_run:
        # Get the SHA1s that will be pushed so that we can add reviewers
        remote = project.review_remote
        remote.parse_url()
        server = remote.server
        username = remote.username
        ssh_port = remote.port
        ui.info("Fetching", remote.name)
        git.fetch(remote.name, "--quiet")
        commits_pushed = git.get_log("%s/%s" % (remote.name, branch), "HEAD")
        sha1s = [commit["sha1"] for commit in commits_pushed]
    git.push(*args)
    if reviewers and not dry_run:
        ui.info("Adding reviewers...", ("(" + ", ".join(reviewers) + ")"))
        try:
            set_reviewers(sha1s, reviewers, username, server, ssh_port)
        except qisys.command.CommandFailedException as e:
            ui.warning("Couldn't set reviewers")
            ui.warning(e)
        else:
            ui.info("Done!")
예제 #16
0
 def push_tag(self, project, tag, branch="master", fast_forward=True):
     """ push tag on project """
     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")
     # tag the branch
     git.call("tag", tag)
     if fast_forward:
         git.push("origin", tag)
     else:
         git.push("origin", "--force", tag)
예제 #17
0
 def push_tag(self, project, tag, branch="master", fast_forward=True):
     """ push tag on project """
     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")
     # tag the branch
     git.call("tag", tag)
     if fast_forward:
         git.push("origin", tag)
     else:
         git.push("origin", "--force", tag)
예제 #18
0
def push(project,  branch, bypass_review=False, dry_run=False,
         reviewers=None, topic=None):
    """ Push the changes for review.

    Unless review is False, in this case, simply update
    the remote gerrit branch

    :param reviewers: A list of reviewers to invite to review

    """
    git = qisrc.git.Git(project.path)
    review_remote = project.review_remote
    args = list()
    if dry_run:
        args.append("--dry-run")
    args.append(review_remote.url)
    if bypass_review:
        args.append("%s:%s" % (branch, branch))
    else:
        ui.info("Pushing code to", review_remote.name, "for review.")
        remote_ref = "refs/for/%s" % branch
        if topic:
            remote_ref = "%s/%s" % (remote_ref, topic)
        args.append("%s:%s" % (branch, remote_ref))
    if reviewers and not dry_run:
        # Get the SHA1s that will be pushed so that we can add reviewers
        remote = project.review_remote
        remote.parse_url()
        server = remote.server
        username = remote.username
        ssh_port = remote.port
        git.fetch(remote.name)
        commits_pushed = git.get_log("%s/%s" % (remote.name, branch), "HEAD")
        sha1s = [commit["sha1"] for commit in commits_pushed]
    git.push(*args)
    if reviewers and not dry_run:
        ui.info("Adding reviewers...")
        try:
            for sha1 in sha1s:
                set_reviewers(sha1, reviewers, username, server, ssh_port)
        except qisys.command.CommandFailedException as e:
            ui.warning("Couldn't set reviewers")
            ui.warning(e)
        else:
            ui.info("Done!")
예제 #19
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))
예제 #20
0
파일: push.py 프로젝트: mikalv/qibuild
def do(args):
    """ Main entry point """
    git_worktree = qisrc.parsers.get_git_worktree(args)
    git_project = qisrc.parsers.get_one_git_project(git_worktree, args)
    git = qisrc.git.Git(git_project.path)
    current_branch = git.get_current_branch()
    if not current_branch:
        ui.error("Not currently on any branch")
        sys.exit(2)
    if git_project.review:
        maintainers = qisrc.maintainers.get(git_project, warn_if_none=True)
        reviewers = [x['email'] for x in maintainers]
        reviewers.extend(args.reviewers or list())
        # Prefer gerrit logins or groups instead of e-mails
        reviewers = [x.split("@")[0] for x in reviewers]
        qisrc.review.push(git_project, current_branch,
                          bypass_review=(not args.review),
                          dry_run=args.dry_run, reviewers=reviewers,
                          topic=args.topic)
    else:
        if args.dry_run:
            git.push("-n")
        else:
            if args.review and not args.yes:
                mess = """\
The project is not under code review.
Are you sure you want to run `git push` ?
This action cannot be undone\
"""
                answer = qisys.interact.ask_yes_no(mess, default=False)
                if answer:
                    git.push()
            else:
                git.push()
예제 #21
0
파일: push.py 프로젝트: aldebaran/qibuild
def do(args):
    """ Main entry point """
    git_worktree = qisrc.parsers.get_git_worktree(args)
    git_project = qisrc.parsers.get_one_git_project(git_worktree, args)
    git = qisrc.git.Git(git_project.path)
    current_branch = git.get_current_branch()
    if not current_branch:
        ui.error("Not currently on any branch")
        sys.exit(2)
    if git_project.review:
        maintainers = qisrc.maintainers.get(git_project, warn_if_none=True)
        reviewers = [x['email'] for x in maintainers]
        reviewers.extend(args.reviewers or list())
        # Prefer gerrit logins or groups instead of e-mails
        reviewers = [x.split("@")[0] for x in reviewers]
        qisrc.review.push(git_project, current_branch,
                          bypass_review=(not args.review),
                          dry_run=args.dry_run, reviewers=reviewers,
                          topic=args.topic)
    else:
        if args.dry_run:
            git.push("-n")
        else:
            if args.review and not args.yes:
                mess = """\
The project is not under code review.
Are you sure you want to run `git push` ?
This action cannot be undone\
"""
                answer = qisys.interact.ask_yes_no(mess, default=False)
                if answer:
                    git.push()
            else:
                git.push()
예제 #22
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