是否可以创建一个 svn 提交钩子来确认工作目录在提交之前已被 svn 更新、构建和测试?我想至少确保在开发人员提交之前,代码已经使用主干中的最新代码进行了编译和测试。当开发人员修改不同的源代码而导致构建失败时,这可以防止主干中出现集成问题。
另一种方法是,如果存在任何已更新的文件(但工作目录中没有必要修改),则阻止提交。
顺便说一句,正如上一个问题中提到的,我的工作提交了二进制文件和源代码。造成这种情况的一个给定原因是,如果提交时存在二进制文件冲突,您就知道该二进制文件的源已发生更改,因此您需要运行 svn-update 并重新编译。它还使合并和更新变得痛苦。我意识到,如果开发人员在提交之前进行更新,则不太可能需要此检查。
我正在使用SVN precommit钩子来验证我的代码标准(PSR2),然后才能提交.只需一个例外就可以完美地工作.我的单元测试(PHPUnit)文件存在我的所有静态单元测试函数的引导类,但也启用了引导类定义之上的错误消息.
PSR2标准在尝试提交时会发出警告,因为您不能在包含类定义的文件中包含不在类或函数中的代码.
有没有人有办法在我的代码中除去这个错误或者让我的代码有效的方法(没有把代码放在bootstrap类的每个静态函数中启用我的错误消息)?
这是文件:
<?php
namespace AlbumTest;
use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;
use RuntimeException;
error_reporting(E_ALL | E_STRICT);
chdir(__DIR__);
class Bootstrap
{
protected static $serviceManager;
protected static $config;
protected static $bootstrap;
public static function init()
{
// Load the user-defined test configuration file, if it exists; otherwise, load
if (is_readable(__DIR__ . '/TestConfig.php')) {
$testConfig = include __DIR__ . '/TestConfig.php';
} else {
$testConfig = include __DIR__ . '/TestConfig.php.dist';
}
$zf2ModulePaths = array();
if (isset($testConfig['module_listener_options']['module_paths'])) {
$modulePaths = …Run Code Online (Sandbox Code Playgroud) 我有一个在 touch python 文件上运行的 git 预提交挂钩autopep8。我的问题是:
# If there are whitespace errors,它print是the offending file names and fail.见下文。)
问题:
如何让它重新添加并重新提交我当前必须手动修复的文件?
谢谢!
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this …Run Code Online (Sandbox Code Playgroud) 我试图阻止 git 提交继续使用预提交挂钩。通过阅读手册,当您返回 0 以外的退出代码时,它应该停止。我正在测试 csscomb 命令是否返回错误,如果返回错误,则中断循环并退出,但 git 提交仍然继续通过 来输入消息git commit (-a)。
我已经从https://github.com/filtercake/git-pre-commit-csscomb分叉并修改了下面的脚本
#!/bin/bash
# pre-commit hook to comb staged .sass and .scss files
# save as .git/hooks/pre-commit
# make executable: chmod +x .git/hooks/pre-commit
# sources:
# http://www.hagenburger.net/BLOG/Using-Git-Commit-Hooks-to-Autocompile-Sass-to-CSS.html
# http://stackoverflow.com/questions/8470755/git-pre-commit-hook-add-file-into-index/8471009#8471009
# http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script/677212#677212
# https://gist.github.com/openam/8406343
# check if sass/scss files are staged for commit
# diff-lines from http://stackoverflow.com/a/12179492/3019532
# takes the line
function diff-lines() {
local path=
local line=
while read; do
esc=$'\033'
if [[ $REPLY =~ ---\ …Run Code Online (Sandbox Code Playgroud) 我想在 gitlab 中使用预提交钩子。我在文档中做所有事情:https : //docs.gitlab.com/ce/administration/custom_hooks.html
在 custom_hooks 目录中,我创建了包含以下内容的预提交文件:
#!/bin/bash
exit 1
Run Code Online (Sandbox Code Playgroud)
钩子永远不会被触发,因为我可以提交。
当我对 pre-receive hook 做同样的事情时 - 一切正常。
如果 Gitlab 不允许使用预提交钩子?
我试图强制执行git commit消息策略,以使我的存储库保持整洁。我看过有关服务器端和客户端挂钩的官方文档,然后碰到了husky。
到目前为止,我可以与第一个一起工作,但无法设置沙哑,我还有很多东西要学习。主要思想是能够在新的工作站上工作而不必手动设置任何客户端挂钩。
有人可以解释我如何设置哈士奇检查我的提交消息,甚至举个例子吗?
这是project-root/githooks文件夹中的commit-msg钩子:
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /([resolved|fixed]) #([0-9])* ([A-Z])\w+/
if !$regex.match(message)
puts "[POLICY] Your message is not formatted correctly!"
puts "Message format must be like:"
puts "resolved #123 Case title (for features)"
puts "fixed #123 Case title (for bugs)"
puts "First letter of 'Case title' must be capitalized!"
exit 1
end
Run Code Online (Sandbox Code Playgroud)
我试图将脚本添加到package.json中:
"scripts": {
... : ...,
"commitmsg": "sh hooks/commit-msg",
... : ...
}
Run Code Online (Sandbox Code Playgroud)
挂钩不起作用。所有消息均通过。如果放在.git / hooks中,它将正常工作。 …
我试图让一个预提交钩子工作,检查交错文件并读取差异以检查几个字符串。如果字符串存在,则提交必须失败。
#!/bin/bash
#import os
echo "Running pre-commit hook"
checks=os.environ["APPSETTING_DEVPASSWORD"],os.environ["APPSETTING_DEVUSER"],os.environ["APPSETTING_DEVPASS_ELMAH"]
git diff --cached --name-status | while read x file; do
if [ "$x" == 'D' ]; then continue; fi
for word in $checks
do
if egrep $word $file ; then
echo "ERROR: Disallowed expression \"${word}\" in file: ${file}"
exit 1
fi
done
done || exit $?
Run Code Online (Sandbox Code Playgroud)
即使文件中存在字符串,它仍然提交文件。任何指导将不胜感激。我对 bash 相当陌生。
我的哈士奇脚本:
"husky": {
"hooks": {
"pre-commit": "sh ./tools/githooks/pre-commit.sh"
}
}
Run Code Online (Sandbox Code Playgroud)
假设我正在做一个git commit -m "I want that text". 如何在 shell 脚本中访问我的提交消息?我试图在 shell 脚本中回显 $HUSKY_GIT_PARAMS 和 $HUSKY_GIT_STDIN 但没有成功
有一个serverless.yaml文件包含这样的行:
VpcId: !Ref MyVpc
Run Code Online (Sandbox Code Playgroud)
Yaml 文件check-yaml git由pre-commit命令调用的钩子验证。所以pre-commit run --all-files运行失败并出现错误:
could not determine a constructor for the tag '!Ref'
in "serverless.yml", line 172, column 29
Run Code Online (Sandbox Code Playgroud)
有没有办法配置check-yaml跳过这个错误?
我正在尝试为我的 Django 项目编写一个预提交钩子,以检查丢失的迁移。也就是说,它确保所有更改都反映在迁移文件中。
实现此目的的一种方法是,如果makemigrations命令未返回任何更改,则 PASS 预提交挂钩。
$ ./manage.py makemigrations --dry-run
No changes detected
Run Code Online (Sandbox Code Playgroud)
如果 pre-commit 钩子返回一些东西,则它会失败:
$ ./manage.py makemigrations --dry-run
Migrations for 'myapp':
myapp/migrations/0003_auto_20201213_2233.py
- Alter field type on event
Run Code Online (Sandbox Code Playgroud)
我该如何编写这个预提交钩子?有没有比使用更好的方法makemigrations?这是我到目前为止所拥有的,但它总是通过(我想我需要解析响应):
repos:
- repo: local
hooks:
- id: pre-commit-django-migrations
name: Check django migrations
entry: ./manage.py makemigrations --dry-run
language: system
types: [python]
pass_filenames: false
Run Code Online (Sandbox Code Playgroud) pre-commit-hook ×10
git ×6
bash ×3
pre-commit ×3
hook ×2
husky ×2
svn ×2
coding-style ×1
django ×1
git-husky ×1
githooks ×1
gitlab ×1
macos ×1
pep8 ×1
php ×1
phpunit ×1
python ×1
tortoisesvn ×1
workflow ×1
yaml ×1