标签: pre-commit

预提交无法安装 isort 5.10.1,并出现错误“RuntimeError:Poetry 配置无效”

[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)

python pre-commit pre-commit-hook isort pre-commit.com

18
推荐指数
2
解决办法
7474
查看次数

通过预提交,如何在提交之前使用一些钩子,在推送之前使用其他钩子

有些钩子可能需要一段时间才能运行,我想在推送之前运行它们,但不是在每次特定提交之前运行(例如,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)

这肯定不是被黑色格式化的。

python git pre-commit pre-commit-hook pre-commit.com

17
推荐指数
1
解决办法
1万
查看次数

如何仅对分阶段内容运行git预提交检查?

假设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)

git pre-commit pre-commit-hook

15
推荐指数
2
解决办法
3687
查看次数

签入TFS 2013之前的代码审查

我正在尝试实现一个流程,以便管理员可以在开发人员签入TFS 2013之前查看所有开发人员的代码.

是否有任何过程需要人工在将代码添加到实际项目之前对其进行审核?

我正在使用TFS 2013和Visual Studio 2013.

pre-commit checkin visual-studio-2013 tfs2013

15
推荐指数
1
解决办法
3万
查看次数

测试将在预提交挂钩中提交的内容

互联网上充斥着对这个问题的不正确和不理想的答案.这是不幸的,因为你会认为这将是你想做的常见事情.

问题:当pre-commit钩子运行时,存储库可能不干净.因此,如果你天真地进行测试,他们就不会反对你提交的内容,而是你的工作树中发生的任何污垢.

最明显的事情是git stash --keep-index --include-untracked在的开始pre-commit,并git pop在出口处.这样你就可以测试(纯)索引,这就是我们想要的.

不幸的是,如果你使用它git add --patch,会生成合并冲突标记(特别是如果你编辑了),因为stash@{0}提交后内容可能与工作树不匹配.

另一个常见的解决方案是克隆存储库并在新的临时存储库中运行测试.这有两个问题:一个是我们还没有提交,所以我们不能轻易地获得我们即将提交的状态的存储库副本(我确信有一种方法可以做到这一点) ,但我不感兴趣,因为:).其次,我的测试可能对当前工作目录的位置敏感.例如,由于本地环境配置.

那么:如何在git stash --keep-index --include-untracked不引入合并冲突标记的情况下将我的工作树恢复到它所处的状态,并且不修改提交后的内容HEAD

git pre-commit pre-commit-hook githooks git-index

14
推荐指数
2
解决办法
4574
查看次数

使用预提交排除一些运行黑色的文件

我想在预提交中配置黑色并从检查任何迁移文件夹中排除预提交。

我的 pyproject.toml 看起来像这样

[tool.black]
line-length = 79
target-version = ['py37']
include = '\.pyi?$'
exclude = '''

(
  /(
      \.eggs
    | \.git
    | \.hg
    | \.mypy_cache
    | \.tox
    | \.venv
    | _build
    | buck-out
    | build
    | dist
  )/
  | ^migrations/
'''
Run Code Online (Sandbox Code Playgroud)

我还配置了预提交。但是在运行pre-commit run --all-files 黑色格式迁移文件夹时,我如何配置黑色

pre-commit python-black pre-commit.com

14
推荐指数
2
解决办法
8016
查看次数

使用预提交挂钩停止特定作者的git提交

我的计划是使用git来跟踪/ etc中的更改但是在提交时我希望让进行更改的人通过在命令行上添加--author选项将自己指定为作者.

所以我想以root身份停止意外提交.

我尝试创建这个预提交钩子但它不起作用 - 即使我在提交行上指定了作者,git var仍然会返回root.

AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
   echo "Please commit under your own user name instead of \"$AUTHOR\":"
   echo 'git commit --author="Adrian"'
   echo "or if your name is not already in logs use full ident"
   echo 'git commit --author="Adrian Cornish <a@localhost>"'
   exit 1
fi
exit 0
Run Code Online (Sandbox Code Playgroud)

git hook pre-commit

13
推荐指数
1
解决办法
5063
查看次数

pylint 和预提交钩子无法导入

我的项目结构如下所示:

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)

pylint pre-commit pre-commit-hook pre-commit.com

13
推荐指数
1
解决办法
1646
查看次数

如何使用 Husky 版本 6 进行 lint-staged 工作

我尝试使用赫斯基pre-commitlint-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)

pre-commit pre-commit-hook eslint husky lint-staged

13
推荐指数
2
解决办法
9190
查看次数

如何确保所有预提交钩子在 CI/CD 中通过

我的团队在我们的存储库中使用预提交来运行各种代码检查和格式化程序。我的大多数队友都使用它,但有些人通过使用git commit --no-verify. 无论如何,是否可以在 CI/CD 中运行某些内容以确保所有预提交挂钩都通过(我们正在使用 GitHub 操作)。如果至少有一个钩子失败,则抛出一个错误。

pre-commit pre-commit-hook pre-commit.com

12
推荐指数
1
解决办法
1万
查看次数