pythonpython-3.xpre-commit-hookpre-commit.comisort

isort a python directory manually and then can't push to remote repository


I am trying to add isort, black and flake8 into my project's pre-commit hooks, it works fine when I edit one single file.

What I want to achieve is isort one directory of the project by isort -rc . and push the changes to remote repository but it gives me Everything up-to-date but when I check git status it shows me all modifications.

Can someone help figure out what I have done wrong? Below I post the screenshot and code snippets. Thanks!

enter image description here ā€¢100% āžœ git status On branch 2020-01-29-test-pre-commit Your branch is up to date with 'origin/2020-01-29-test-pre-commit'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   athlete_report/algorithm/yazs/cc_calculation_copy.py
    modified:   athlete_report/algorithm/yazs/dto/session_event.py
    modified:   athlete_report/algorithm/yazs/formula/flow_processor.py
    modified:   athlete_report/algorithm/yazs/input/flow_input_processor.py
    modified:   athlete_report/algorithm/yazs/input/single_source_handler.py
    modified:   athlete_report/algorithm/yazs/input/two_sources_handler.py
    modified:   athlete_report/algorithm/yazs/vertical_jump/vert_jump.py
    modified:   athlete_report/algorithm/yazs/yazs_calculation.py
    modified:   athlete_report/pdf_generator/athlete_report_builder.py

(mbp37)
src on ī‚  2020-01-29-test-pre-commit [+] via šŸ…’ mbp37
ā€¢100% āžœ git add .
(mbp37)
src on ī‚  2020-01-29-test-pre-commit [+] via šŸ…’ mbp37
ā€¢100% āžœ git commit -am "add modifications to athlete report"
seed isort known_third_party.............................................Passed
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /Users/hzhang/Work/yana-motion-lab/report-engine/src/athlete_report/pdf_generator/athlete_report_builder.py

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted /Users/hzhang/Work/yana-motion-lab/report-engine/src/athlete_report/pdf_generator/athlete_report_builder.py
All done! āœØ šŸ° āœØ
1 file reformatted, 8 files left unchanged.

Flake8...................................................................Passed
(mbp37)
src on ī‚  2020-01-29-test-pre-commit [+] via šŸ…’ mbp37 took 3s
ā€¢100% āžœ git diff
(mbp37)
src on ī‚  2020-01-29-test-pre-commit [+] via šŸ…’ mbp37
ā€¢100% āžœ git push
Everything up-to-date
(mbp37)
src on ī‚  2020-01-29-test-pre-commit [+] via šŸ…’ mbp37 took 2s
ā€¢100% āžœ git diff

Solution

  • Because changes were made by pre-commit the commit was cancelled (as the contents were not correct to be committed)

    You'll want to review the changes being made (git status / git diff) and if the automatic changes made by the tools look correct you'll then git add -u and re-run your git commit command (^R + git commit might be helpful here)

    there's no commit to push because the commit was cancelled