簡體   English   中英

如何確保提交包含共享 git 存儲庫而不是組 email id 中的特定用戶信息?

[英]How to ensure that commit contains specific user info in a shared git repository instead of group email id?

我們有一個開發服務器,團隊成員使用普通 unix 用戶登錄並在同一個存儲庫上工作。 每個團隊成員可以克隆到不同的存儲庫並使用他/她的身份配置本地 git 用戶身份並刪除全局 git 用戶身份。 但是,無論他們如何工作,強制每個提交都具有特定用戶身份而不是普通 unix 用戶身份的最佳方法是什么? 我正在考慮使用預接收服務器掛鈎來檢查有效的user.nameuser.email 我該如何做到這一點? 我使用本地 GitLab。 任何建議和見解都值得贊賞。

GitLab 是否允許您安裝自己的掛鈎? 如果是這樣,您只需閱讀pre-receive掛鈎並編寫類似這樣的內容。 這個例子是perl但你可以使用bash或任何你喜歡的。

#!/usr/bin/perl
while(<STDIN>)
{
    my ($commit_old, $commit_new, $commit_ref) = ($_ =~ m/^(.*?)\s(.*?)\s(.*)$/);

    open(CHUNKS, "git rev-list --first-parent $commit_old..$commit_new |");
    while(my $commit_chunk = <CHUNKS>)
    {
        chomp $commit_chunk;

        my $cn = `git --no-pager show -s --format='%cn' $commit_chunk`; chomp $cn;
        my $ce = `git --no-pager show -s --format='%ce' $commit_chunk`; chomp $ce;

        my $an = `git --no-pager show -s --format='%an' $commit_chunk`; chomp $an;
        my $ae = `git --no-pager show -s --format='%ae' $commit_chunk`; chomp $ae;

        if (! .. check author name, author email, committer name, committer email however you like against the common identity ...)
        {
            print("Hey you, that's wrong. How many times I have to tell you not to use the common identity?!?!\n;");
            exit 1;
        }
    }
}
exit 0;

(為了清楚起見,刪除了錯誤檢查,檢查新分支(在 repo 中有和沒有提交)、刪除的分支等。正如他們所說,這些“留給讀者作為練習”。)

暫無
暫無

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

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