我想使用预提交挂钩,阻止开发人员在非根目录上设置svn:mergeinfo.也就是说,我想强制执行svn:mergeinfo 只能在"trunk"或"branches/branchName"这样的目录上设置.开发人员有时需要"提醒"使用根目录的子目录作为合并目标(根据此处列出的最佳实践)并不是一种好的做法.有没有人有这样的钩子脚本或知道我在哪里找到一个?我在Windows环境中,所以批处理或powershell会更好,但任何东西肯定会有所帮助.
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
[...]
stderr:
ERROR: Command errored out with exit status 1:
[...]
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/factory.py", line 57, in create_poetry
raise RuntimeError("The Poetry configuration is invalid:\n" + message)
RuntimeError: The Poetry configuration is invalid:
- …Run Code Online (Sandbox Code Playgroud) 我想在提交Mercurial或Git repo之前运行JSLint.
我希望这是一个自动步骤,而不是依赖于开发人员(主要是我)记住之前运行JSLint.我通常在开发时运行JSLint,但是想要在JS文件上指定一个合同,它们在提交到repo之前传递JSLint.
对于Mercurial,此页面说明了预先提交的语法,但似乎唯一可用的变量是提交中涉及的parent1和parent2变更集ID.我真正想要的是提交涉及的文件名列表,以便我可以选择.js文件并对它们运行jslint.
对于GIT类似的问题,作为预提交脚本的一部分提供的默认信息似乎有限.
可能有用的是调用hg status/git status作为precommit脚本的一部分,解析该输出以查找JS文件,然后以这种方式执行工作.我希望有一些更简单的东西,我不确定调用状态作为预先提交钩子的一部分是否反映了正确的信息.例如在Git中,如果尚未添加更改文件,但git commit使用-a,那么文件是否会在git status输出的正确部分中显示为提交集的一部分?
更新:我有一些工作,它在这里可见:http://github.com/jrburke/dvcs_jslint/
有些钩子可能需要一段时间才能运行,我想在推送之前运行它们,但不是在每次特定提交之前运行(例如,pylint 可能有点慢)。
我见过以下内容:
但目前还不清楚我应该如何设置它。
这是我尝试过的:
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
stages: [push]
Run Code Online (Sandbox Code Playgroud)
由此,我期望前几个钩子在提交之前运行(它们确实如此),但我期望黑色在推送之前运行,但事实并非如此。
为了测试我是否创建了以下文件:
"""This is a docstring."""
print('this should be formatted')
Run Code Online (Sandbox Code Playgroud)
这肯定不是被黑色格式化的。
目前我们正在使用SVN.我想开始使用GitHub,但一个绝对要求是我们需要像我们现在一样对代码进行预先(premerge)验证.GitHub是否支持precommithooks(premergehooks)?
我们是一个由5名开发人员组成的团队.我们达成了一个协议,所有代码(JavaScript)都应该通过类似JSLint的验证.事实证明,自愿验证不起作用,因为它很容易被遗忘.我们怎样才能确保其他人可用的代码能够保证对JSLint(或类似的)进行验证?
假设git status给出了这个:
# On branch X
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: file1.cc
# modified: file1.h
# modified: file1_test.cc
# modified: SConscript
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: file1.cc
# …Run Code Online (Sandbox Code Playgroud) 互联网上充斥着对这个问题的不正确和不理想的答案.这是不幸的,因为你会认为这将是你想做的常见事情.
问题:当pre-commit钩子运行时,存储库可能不干净.因此,如果你天真地进行测试,他们就不会反对你提交的内容,而是你的工作树中发生的任何污垢.
最明显的事情是git stash --keep-index --include-untracked在的开始pre-commit,并git pop在出口处.这样你就可以测试(纯)索引,这就是我们想要的.
不幸的是,如果你使用它git add --patch,会生成合并冲突标记(特别是如果你编辑了),因为stash@{0}提交后内容可能与工作树不匹配.
另一个常见的解决方案是克隆存储库并在新的临时存储库中运行测试.这有两个问题:一个是我们还没有提交,所以我们不能轻易地获得我们即将提交的状态的存储库副本(我确信有一种方法可以做到这一点) ,但我不感兴趣,因为:).其次,我的测试可能对当前工作目录的位置敏感.例如,由于本地环境配置.
那么:如何在git stash --keep-index --include-untracked不引入合并冲突标记的情况下将我的工作树恢复到它所处的状态,并且不修改提交后的内容HEAD?
我的项目结构如下所示:
project/
app/
main.py
venv/
.pylintrc
.pre-commit-config.yaml
Run Code Online (Sandbox Code Playgroud)
当我尝试编辑project/app/main.py但失败时
Unable to import 'psycopg2' (import-error)
Run Code Online (Sandbox Code Playgroud)
但是当我试图直接对这个文件进行 pylint 时,它可以工作。
.pre-commit-config.yaml 看起来像这样:
- repo: https://github.com/PyCQA/pylint
rev: pylint-2.4.2
hooks:
- id: pylint
Run Code Online (Sandbox Code Playgroud) 我尝试使用赫斯基pre-commit和lint-staged.
安装了这些:
"husky": "^5.1.3",
"lint-staged": "^10.5.4",
Run Code Online (Sandbox Code Playgroud)
在 package.json 我有:
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src --color",
"isready": "npm run format && npm run lint && npm run build"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test",
}
},
"lint-staged": {
"./src/*.{js,jsx,ts,tsx}": [
"npm run …Run Code Online (Sandbox Code Playgroud)