簡體   English   中英

如何在gitlab服務器端預接收鈎子中獲取提交消息

[英]How to get commit message in gitlab server side pre-receive hooks

我正在嘗試在gitlab上開發服務器端預接收鈎子。 我應該從正在添加的新提交中獲取提交消息。

我嘗試使用git log --pretty=%B -n 1 這將返回舊的已提交消息。 如何從新的未接受的更改中獲取提交消息?

當我嘗試將refname或參數添加到腳本中時,它沒有任何值。 (認為​​可能會有幫助)

#!/bin/bash
ref_name=$refname
echo $ref_name
ref_name=$1
echo $ref_name
echo "refname"
issue=`git log --pretty=%B -n 1`
echo $issue #this is printing old commit message

結果:

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 306 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote:
remote:
remote: refname

pre-receive掛鈎在標准輸入上獲取引用及其舊版本和新版本的列表。 因此,您可以執行以下操作:

#!/bin/sh

while read old new ref
do
    # ref deleted; skip
    echo "$new" | grep -qsE '^0+$' && continue

    issue=$(git log --pretty=%B -n 1 "$new")
    echo "issue is $issue"
done

請注意,這是假設您只關心最新引用的頭提交,並且您也可以對標簽執行此操作。 如果只希望分支,並且想遍歷所有提交,則可以執行以下操作:

#!/bin/sh

while read old new ref
do
    case $ref in
        refs/heads/*)
            if echo "$new" | grep -qsE '^0+$'
            then
                # ref deleted; skip
                :
            elif echo "$old" | grep -qsE '^0+$'
            then
                # new branch
                # do something with this output
                git log --pretty=%B "$new"
            else
                # update
                # do something with this output
                git log --pretty=%B "$old".."$new"
            fi;;
        *)
            continue;;
    esac
done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM