我正在尝试用玩笑对预提交挂钩中的暂存文件运行测试。到现在为止还挺好。让它与pre-commit和lint-stagedNPM 包一起工作。
来自 package.json 的片段:
{
// ...
"scripts": {
"hook": "lint-staged",
// ...
},
"devDependencies": {
"eslint": "^4.12.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.3.1",
"jest": "^22.0.3",
"jest-junit": "^3.4.0",
"lint-staged": "^6.0.1",
"pre-commit": "^1.2.2",
"prettier": "^1.9.1"
},
"jest": {
"collectCoverageFrom": ["src/**/*.js"],
"coveragePathIgnorePatterns": ["<rootDir>/src/models/"],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"pre-commit": ["hook"],
"lint-staged": {
"*.js": ["eslint --fix", "git add", "jest --bail --passWithNoTests --coverage"]
},
// ...
} …Run Code Online (Sandbox Code Playgroud) 是否有办法准确指定git-hook使用时要跳过哪些内容--no-verify?--no-verify或者除了完成此任务之外还有其他标志吗?也许只是一个只能跳过的标志pre-commit?
我有两个经常使用的钩子,pre-commit和commit-msg。pre-commit运行我的 linting、流程检查和一些单元测试。commit-msg将我的分支名称附加到提交消息的末尾。
有时我很想跑,--no-verify但pre-commit还是想跑commit-msg。
似乎有很多与此类似的 SO 帖子,但没有什么比选择性跳过--no-verify.
我正在尝试编写一个 git 预提交挂钩,但我需要它兼容 Windows 和 Mac(多个不同的开发机器),或者至少有某种方法来检测操作系统并更改为适当的环境。
我知道如果将我的 shebang 设置为
#!C:/Program\ Files/Git/usr/bin/sh.exe
Run Code Online (Sandbox Code Playgroud)
然后 Windows 将切换为使用 git bash 执行。
Mac 上也是如此
#!/bin/bash
Run Code Online (Sandbox Code Playgroud)
设置 bash 执行环境。
但如果钩子有错误的 shebang,它甚至不会读取它。我需要一种方法来区分操作系统并相应地设置 shebang。
为 Mac 和 Windows 创建单独的钩子,并将它们单独安装在机器上是不可能的,因为这会使代码维护/重构变得不可能。
想法?
我克隆了一个存储库,安装了 pre-commit 并且是第一次提交。 这是实际安装和设置预提交包的时间。我遇到了以下问题。
[INFO] Installing environment for https://github.com/asottile/seed-isort-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/roopak/.cache/pre-commit/repokb2ckm/py_env-python2.7/bin/python', u'/home/roopak/.cache/pre-commit/repokb2ckm/py_env-python2.7/bin/pip', 'install', '.')
return code: 1
expected return code: 0
stdout:
Processing /home/roopak/.cache/pre-commit/repokb2ckm
stderr:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个配置,.pre-commit-config.yaml以排除在某些分支上运行预提交,或者只在某些分支上运行它。我不知道这个功能是否没有实现,或者我是否在文档中遗漏了它。
谢谢!
我在安装预提交挂钩时遇到了障碍。根据下面的错误,挂钩安装在目录中找不到 python exe C:\\\\Users\\\\dangler\\\\.cache\\\\pre-commit\\\\repoith5dg7x\\\\py_env-default\\\\Scripts\\\\python.EXE(该文件夹中不存在 python.EXE...应该吗?)。我\xe2\x80\x99在过去的几个小时里一直在尝试解决它,但没有成功。希望有一个解决方案,也许我已经搜索了错误的地方。
(fiddle-env) PS C:\\Users\\dangler\\Documents\\projects\\fiddle> pre-commit clean\n(fiddle-env) PS C:\\Users\\dangler\\Documents\\projects\\fiddle> pre-commit install\n(fiddle-env) PS C:\\Users\\dangler\\Documents\\projects\\fiddle> git commit -am "README file with links"\n[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.\n[INFO] Once installed this environment will be reused.\n[INFO] This may take a few minutes...\nAn unexpected error has occurred: CalledProcessError: command: ('C:\\\\Users\\\\dangler\\\\.cache\\\\pre-commit\\\\repookmqanwy\\\\py_env-default\\\\Scripts\\\\python.EXE', '-mpip', 'install', '.')\nreturn code: 3221225781\nexpected return code: 0\nstdout: (none)\nstderr: (none)\nCheck the log at C:\\Users\\dangler\\.cache\\pre-commit\\pre-commit.log\nRun Code Online (Sandbox Code Playgroud)\n该.pre-commit-config.yml文件是这样的:
repos:\n- repo: https://github.com/pre-commit/pre-commit-hooks\n rev: v2.4.0\n hooks:\n - id: double-quote-string-fixer\n - id: check-added-large-files\n …Run Code Online (Sandbox Code Playgroud) 我在运行“pre-commit run --all-files”时收到以下错误,并且在尝试提交时出现以下错误,这是一些 python 错误,使用的 python 版本是“Python 2.7.16”。
\n[INFO] Installing environment for https://github.com/pre-commit/mirrors-mypy.\n[INFO] Once installed this environment will be reused.\n[INFO] This may take a few minutes...\nAn unexpected error has occurred: CalledProcessError: command: ('/Users/user/.cache/pre-commit/repoq_mv31g8/py_env-default/bin/python', '-mpip', 'install', '.', 'tokenize-rt==3.2.0', 'pydantic')\nreturn code: 1\nexpected return code: 0\nstdout:\n Processing /Users/user/.cache/pre-commit/repoq_mv31g8\n Preparing metadata (setup.py): started\n Preparing metadata (setup.py): finished with status 'done'\n Collecting tokenize-rt==3.2.0\n Using cached tokenize_rt-3.2.0-py2.py3-none-any.whl (6.1 kB)\n Collecting pydantic\n Using cached pydantic-1.9.0-cp310-cp310-macosx_11_0_arm64.whl (2.4 MB)\n Collecting mypy==0.782\n Using cached mypy-0.782-py3-none-any.whl (2.4 MB)\n Collecting mypy-extensions<0.5.0,>=0.4.3\n …Run Code Online (Sandbox Code Playgroud) 我最近从我的环境中卸载了预提交。我在 pipelinev 中执行了以下操作:
pipenv --rm
<deleted Pipfile and Pipfile.lock>
pipenv install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
我确保预提交模块不再位于requirements.txt 中。当我进行 git 提交时,我得到:
~/my_project/.venv/bin/python: No module named pre_commit
Run Code Online (Sandbox Code Playgroud)
这阻止了我提交,而且我不知道这是从哪里来的,因为未安装预提交。此外,指定的回溯路径指向 python 而不是 python3。我缺少什么?
我需要做以下事情:
在Perl中编写预提交钩子
Hook应该检查所有提交的文件是否存在某些文本,如果找不到该文本则会失败
基本上,我需要一个Perl钩子的例子来读取被提交的文件.
我真的在寻找一些代码最少的优雅解决方案.
注意:Hook应该使用svnlook或其他更好的方式来查找文件.
是否可以在CVS的预提交钩子中使用提交消息?CVS服务器正在远程运行,我使用它来访问它pserver.
理想情况下,如果文件通过过滤器或提交消息包含某些文本,我想允许提交.
我没有选择使用其他版本控制系统.
pre-commit-hook ×10
pre-commit ×6
git ×5
githooks ×2
apple-m1 ×1
bash ×1
commit ×1
conda ×1
cvs ×1
javascript ×1
jestjs ×1
mypy ×1
node.js ×1
perl ×1
pipenv ×1
python ×1
python-3.x ×1
svn ×1