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)
def guess_emails(git, reviewers): """ Fix the reviewer list. Complete the email addresses with the committer email's domain name when just the reviewer username is given, using the domain name of the 'user.email' setting from the given git. :return: the list of reviewers' email """ domain_name = git.get_config("user.email") domain_name = domain_name.rsplit("@")[1] for idx, reviewer in enumerate(reviewers): if "@" not in reviewer: reviewers[idx] = reviewer + "@" + domain_name return reviewers
def test_apply_git_config(git_worktree): """ Test Appli Git Config """ foo1 = git_worktree.create_git_project("foo") upstream = Remote() upstream.name = "upstream" upstream.url = "git@srv:bar.git" foo1.configure_remote(upstream) foo1.apply_config() git = qisrc.git.Git(foo1.path) assert git.get_config("remote.upstream.url") == "git@srv:bar.git" foo1.configure_branch("master", tracks="upstream") foo1.apply_config() assert git.get_tracking_branch("master") == "upstream/master" foo1.configure_branch("feature", tracks="upstream", remote_branch="remote_branch") foo1.apply_config() assert git.get_tracking_branch("feature") == "upstream/remote_branch"
def test_apply_git_config(git_worktree): """ Test Appli Git Config """ foo1 = git_worktree.create_git_project("foo") upstream = Remote() upstream.name = "upstream" upstream.url = "git@srv:bar.git" foo1.configure_remote(upstream) foo1.apply_config() git = qisrc.git.Git(foo1.path) assert git.get_config("remote.upstream.url") == "git@srv:bar.git" foo1.configure_branch("master", tracks="upstream") foo1.apply_config() assert git.get_tracking_branch("master") == "upstream/master" foo1.configure_branch( "feature", tracks="upstream", remote_branch="remote_branch" ) foo1.apply_config() assert git.get_tracking_branch("feature") == "upstream/remote_branch"
def guess_emails(git, reviewers): """ Fix the reviewer list. Complete the email addresses with the committer email's domain name when just the reviewer username is given, using the domain name of the 'user.email' setting from the given git. :return: the list of reviewers' email """ domain_name = git.get_config("user.email") if not domain_name: message = "Error: no user.email entry in the git configuration.\n" message += " Set your git configuration:\n" message += " $ git config --global user.name \"John Doe\"\n" message += " $ git config --global user.email \"[email protected]\"\n" raise Exception(message) domain_name = domain_name.rsplit("@")[1] for idx, reviewer in enumerate(reviewers): if "@" not in reviewer: reviewers[idx] = reviewer + "@" + domain_name return reviewers