python 发送--no-ff和评论约定

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 发送--no-ff和评论约定相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python3
"""
Shipit script will shipt all commits from a given feature branch
as a single non fast forward merge, while adding the proper agreed upon
commit message formatting.

You must sit on a local clone of the target branch.
If you are happy with how shipit merged, you just "git push" the result
to the remote branch.
"""
import argparse
import os
import pwd
import subprocess


def ask_if_missing(label, value):
    """
    Asks for user input for label on no value.

    Otherwise it returns the value itself.
    """
    if value:
        return value
    # pylint: disable=bad-builtin
    return input("{}: ".format(label))


def build_commit_msg(author, reviewers, from_branch, to_branch, msg, mp):
    """Builds the agreed convention merge commit message"""
    return "Merge {} into {}\n\n{}\n\n[a={}] [r={}]\nMP: {}".format(
        from_branch, to_branch, msg, author, reviewers, mp)


def build_merge_cmd(from_branch, commit_msg, summary):
    """Builds the merge command."""
    return ["git", "merge", "--no-ff", from_branch, "-m",
            "{}".format(commit_msg), "-e" if not summary else ""]


def main():
    """Invokes the commit building with proper user inputs."""
    current_user = pwd.getpwuid(os.getuid()).pw_name
    parser = argparse.ArgumentParser(
        description='Ship approved MP commits to LP as a --no-ff merge')
    parser.add_argument('--author', '-a', default=current_user,
                        help='Author LP login')
    parser.add_argument('--reviewers', '-r',
                        help=('Comma-separated list of LP reviewer logins'
                              '(at least 2)'))
    parser.add_argument('--feature_branch', '-f',
                        help='Feature branch name to merge')
    parser.add_argument('--target', '-t', default='devel',
                        help='Target branch to merge to')
    parser.add_argument('--message', '-m', default=None,
                        help='Merge MP branch commit message.')
    parser.add_argument('--MP',
                        help='Link to the LP Merge Proposal')
    args = parser.parse_args()

    reviewers = ask_if_missing('Reviewers', args.reviewers)
    feature_branch = ask_if_missing('Feature branch', args.feature_branch)
    mp = ask_if_missing('MP', args.MP)

    commit_msg = build_commit_msg(args.author,
                                  reviewers,
                                  feature_branch,
                                  args.target,
                                  args.message if args.message else '',
                                  mp)
    cmd = build_merge_cmd(feature_branch, commit_msg, args.message)
    print(" ".join(cmd))
    p = subprocess.Popen(cmd)
    p.communicate()


if __name__ == "__main__":
    main()

以上是关于python 发送--no-ff和评论约定的主要内容,如果未能解决你的问题,请参考以下文章

[git] git merge 和 git merge --no-ff

git merge 和 git merge --no-ff

git merge 和 git merge --no-ff

get merge --no-ff和git merge区别git fetch和git pull的区别

git merge 和 git merge --no-ff的区别

Python爬虫系列 - 初探:爬取旅游评论