【问题标题】:How to append Change-id to commit message inside custom commit-msg hook?如何将 Change-id 附加到自定义 commit-msg 挂钩内的提交消息?
【发布时间】:2021-03-18 01:30:30
【问题描述】:

我已经准备好自己的提交消息模板和 commit-msg 钩子用于验证目的。这个钩子是一个简单的 Python 脚本。它可以工作,但我希望在我的提交消息的底部也有 Change-id。 我看到从 gerrit 我可以下载用 Bash 编写的 commit-msg 钩子,这个钩子为 Change-id 生成提供了解决方案: https://gerrit-review.googlesource.com/Documentation/user-changeid.html。 但现在我有 2 个不同的 commit-msg 钩子。那么我应该重写自己的 msg-hook 并将其附加到官方的 msg-hook 模板中,还是应该编写自己的 Change-id 生成器实现?

【问题讨论】:

    标签: python git hook gerrit


    【解决方案1】:

    通过将 $1 输入参数替换为您的脚本输出来修改原始 commit-msg 钩子开头的 MSG 变量定义

    #!/bin/sh
    # From Gerrit Code Review 2.14.20-179-g6c46f4efba
    #
    # Part of Gerrit Code Review (https://www.gerritcodereview.com/)
    #
    # Copyright (C) 2009 The Android Open Source Project
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #
    
    unset GREP_OPTIONS
    
    CHANGE_ID_AFTER="Bug|Depends-On|Issue|Test|Feature|Fixes|Fixed"
    MSG=`python /path/to/myscript.py`
    
    # Check for, and add if missing, a unique Change-Id
    #
    add_ChangeId() {
            clean_message=`sed -e '
    
    

    【讨论】:

    • 那个味精参数是什么?我的 python 脚本输出为 0 - 验证通过或 1 - 验证失败。
    • MSG 变量包含提交消息 - 默认情况下,它是 commit-msg 脚本的第一个输入参数。所以你的最终提交消息将是 0 - 验证通过并且更改 ID
    猜你喜欢
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 2011-03-25
    • 2013-10-16
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多