0

here is my pre-commit-config.yaml

default_language_version:
    # force all unspecified python hooks to run python3
    python: python3
fail_fast: true
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    -   id: check-ast
    -   id: check-byte-order-marker
    -   id: check-builtin-literals
    -   id: check-case-conflict
    -   id: check-docstring-first
    -   id: check-json
    -   id: pretty-format-json
        args: [--autofix]
    -   id: check-merge-conflict
    -   id: check-symlinks
    -   id: check-toml
    -   id: check-vcs-permalinks
    -   id: check-xml
    -   id: check-yaml
    -   id: debug-statements
    -   id: detect-aws-credentials
    -   id: detect-private-key
    -   id: end-of-file-fixer
    -   id: file-contents-sorter
    -   id: fix-encoding-pragma
    -   id: forbid-new-submodules
    -   id: mixed-line-ending
    -   id: name-tests-test
    -   id: no-commit-to-branch
        args: [--branch, develop, --branch, master]
    -   id: requirements-txt-fixer
    -   id: sort-simple-yaml
    -   id: trailing-whitespace
-   repo: https://github.com/pre-commit/mirrors-autopep8
    rev: v1.4.4
    hooks:
    -   id: autopep8
-   repo: https://github.com/pre-commit/pre-commit
    rev: v1.18.3
    hooks:
    -   id: validate_manifest
-   repo: https://github.com/asottile/pyupgrade
    rev: v1.25.1
    hooks:
    -   id: pyupgrade
-   repo: meta
    hooks:
    -   id: check-useless-excludes
-   repo: https://github.com/ambv/black
    rev: 19.3b0
    hooks:
    - id: black
      language_version: python3.7
      args: [-S, -l 99, --exclude="migrations|.venv|node_modules"]
-   repo: https://github.com/egichuri/mirrors-future
    rev: 1fed4cb06bab1cc93e42b080b6645dd47e029b04
    hooks:
    - id: future
-   repo: https://github.com/asottile/seed-isort-config
    rev: v1.9.3
    hooks:
    -   id: seed-isort-config
-   repo: https://github.com/pre-commit/mirrors-isort
    rev: v4.3.21
    hooks:
    -   id: isort

After running git add . then git commit, most test pass but then when i try to push some changes to remote repository it says, changes are upto date.

However when i try to switch branches, the output is some files should be committed.

error: Your local changes to the following files would be overwritten by checkout:
        backend/.gitignore
        backend/users/models.py
        frontend/.gitignore
Please commit your changes or stash them before you switch branches.
Aborting

when i check git status i can see files that need to be commited

here is the output:

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   .pre-commit-config.yaml
        modified:   backend/.gitignore
        modified:   backend/backend/__pycache__/settings.cpython-38.pyc
        modified:   backend/db.sqlite3
        modified:   backend/users/migrations/0001_initial.py
        modified:   backend/users/models.py
        modified:   frontend/.gitignore
        modified:   setup.cfg

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   frontend/.gitignore

Any assistance would be appreciated as i'm unable to continue coding in another branch.

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
kefa mutuma
  • 41
  • 1
  • 7
  • 1
    Did it report errors after `git commit`? – ElpieKay Jun 11 '20 at 07:01
  • `Fix End of Files.........................................................Failed - hook id: end-of-file-fixer - exit code: 1 - files were modified by this hook Fixing frontend/.gitignore` ->This was the only error but unable to resolve it as well – kefa mutuma Jun 11 '20 at 07:03
  • 1
    If the error is printed by `pre-commit`, `git commit` must have failed. Try to add a newline at the end of `frontend/.gitignore`. – ElpieKay Jun 11 '20 at 07:04
  • 1
    It seems the hook has added the newline and fix the issue for you. What you need to do is `git add frontend/.gitignore` and `git commit` again. – ElpieKay Jun 11 '20 at 07:19
  • The formatter automatically does that, then i `git add .` and `git commit` and the precommit runs and gets stuck at this point: ` Forbid new submodules.................................................... ` having challenges proceeding beyond these pre-commit requirements to push changes. – kefa mutuma Jun 11 '20 at 07:19
  • 1
    It seems you have added and committed one or more git submodules. It's not allowed. – ElpieKay Jun 11 '20 at 07:27
  • @ElpieKay any trick to get past this `Forbid new submodules`? running the commit keeps getting stuck at this point. – kefa mutuma Jun 11 '20 at 07:28
  • You mean having two .gitignore files? i thought to have two .gitignore files for the backend and the frontend folders so as to ignore the npm modules in the frontend directory and django modules. Could that be the problem here and resolve to put one .gitignore file in the root directory? Thanks for pointing that out. – kefa mutuma Jun 11 '20 at 07:31
  • 1
    No. A submodule is a nested git repository. I have no idea what your repo is like. Maybe you could ask the repository owner for more help. – ElpieKay Jun 11 '20 at 08:27
  • Thank you @ElpieKay for highlighting some of the problems. With multiple tweeking, I realized its an OS compatibility issue. I am using windows and most of the checks seem to fail while they work with Ubuntu users. I have to run `git commit -m "" --no-verify` to be able to commit and push to the remote repo and have to manually do the changes after builds fail on circle-ci. – kefa mutuma Jun 11 '20 at 09:08

0 Answers0