Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

git - VSCode Restage Staged Files After Precommit Hooks Fail in order to Commit Again

I have a Django project with several pre-commit hooks with Python's pre-commit tool, configured as below:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.0.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files

  - repo: https://github.com/python/black
    rev: master
    hooks:
      - id: black
  - repo: https://github.com/asottile/seed-isort-config
    rev: master
    hooks:
      - id: seed-isort-config
  - repo: https://github.com/pre-commit/mirrors-isort
    rev: master
    hooks:
      - id: isort
  -   repo: https://gitlab.com/pycqa/flake8
      rev: master
      hooks:
      -   id: flake8

Normally, I do below when a commit fails due to pre-commit hooks on terminal:

git add foo.py
git commit -m "added foo"
# pre-commit runs and fails
# black, end-of-file-fixer fixes staged files
git add foo.py # add fixed files again
git commit -m "added foo"
# this time, runs successfully

I'd like to get the same behavior from VSCode.

git panel of vscode

I stage my changes, write commit message and commit. VSCode naturally fails.

vscode fails on commit

No matter how many times I commit on VSCode, it does not "stage" the automatic changes made by black and end-of-file-fixer. So, when I click again, I'd like VSCode to add the files again because their contents are updated. How can I do this?

Thanks in advance.


Environment

  • VSCode 1.52.1
  • Git 2.25.1
  • pre-commit 2.9.3

If relevant:

  • Kubuntu 20.04.1
  • Python 3.8

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share

1.2m questions

2.1m answers

5 comments

56.5k users

...