我正在服务器端编写更新挂钩。 我已成功完成并受到限制。 1.文件大小 2.文件扩展名 我现在要做的是,检查消息并仅接受该内容字符串,说“INFO:”。
我已经使用git log检查了update钩子,但它只给出了已经接受的结果。 在接受/推送更改到存储库之前,我应该怎么做才能检查消息。
I am writing update hook on server side. I have succesfully done and restricted. 1. File size 2. File extensions What I want to do now, to check message and accept only if that contents string, say "INFO:".
I have checked with git log in update hook, but it gives already accepted results only. What should I do to check message before accepting/pushing changes into repository.
最满意答案
你可以从官方的git网站上看看这个网站: 自定义Git - Git强制策略的一个例子
它有一个与你非常相似的用例。 具体这一部分:
$regex = /\[ref: (\d+)\]/ # enforced custom commit message format def check_message_format missed_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n") missed_revs.each do |rev| message = `git cat-file commit #{rev} | sed '1,/^$/d'` if !$regex.match(message) puts "[POLICY] Your message is not formatted correctly" exit 1 end end end check_message_formatYou can take a look at this site from the official git website: Customizing Git - An Example Git-Enforced Policy
It has a use-case that is very much like yours. Specifically this part:
$regex = /\[ref: (\d+)\]/ # enforced custom commit message format def check_message_format missed_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n") missed_revs.each do |rev| message = `git cat-file commit #{rev} | sed '1,/^$/d'` if !$regex.match(message) puts "[POLICY] Your message is not formatted correctly" exit 1 end end end check_message_formatGit Hooks:远程存储库应该接受push,只有在提交消息内容特定的字符串时(Git Hooks: remote repository should accept push, only if commit message contents particular string)我正在服务器端编写更新挂钩。 我已成功完成并受到限制。 1.文件大小 2.文件扩展名 我现在要做的是,检查消息并仅接受该内容字符串,说“INFO:”。
我已经使用git log检查了update钩子,但它只给出了已经接受的结果。 在接受/推送更改到存储库之前,我应该怎么做才能检查消息。
I am writing update hook on server side. I have succesfully done and restricted. 1. File size 2. File extensions What I want to do now, to check message and accept only if that contents string, say "INFO:".
I have checked with git log in update hook, but it gives already accepted results only. What should I do to check message before accepting/pushing changes into repository.
最满意答案
你可以从官方的git网站上看看这个网站: 自定义Git - Git强制策略的一个例子
它有一个与你非常相似的用例。 具体这一部分:
$regex = /\[ref: (\d+)\]/ # enforced custom commit message format def check_message_format missed_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n") missed_revs.each do |rev| message = `git cat-file commit #{rev} | sed '1,/^$/d'` if !$regex.match(message) puts "[POLICY] Your message is not formatted correctly" exit 1 end end end check_message_formatYou can take a look at this site from the official git website: Customizing Git - An Example Git-Enforced Policy
It has a use-case that is very much like yours. Specifically this part:
$regex = /\[ref: (\d+)\]/ # enforced custom commit message format def check_message_format missed_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n") missed_revs.each do |rev| message = `git cat-file commit #{rev} | sed '1,/^$/d'` if !$regex.match(message) puts "[POLICY] Your message is not formatted correctly" exit 1 end end end check_message_format
发布评论