★ wanayoo — archive 1999 https://github.com/pre-commit/pre-commit/pull/1031Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advice to "Files were modified…" error #1031

Closed
wants to merge 2 commits into from

Conversation

@katrinleinweber
Copy link

@katrinleinweber katrinleinweber commented May 12, 2019

Would it make sense to include something like this? If yes, please let me know whether the formatting for a string that should not be too long in the source code, but single-line in the out-put is correct.

Afterwards, I'll:

output.write('Files were modified by this hook.')
output.write('Files were modified by this hook.' \
'Please review them in Git\'s staging area, ' \
'and repeat the commit.')

This comment has been minimized.

@asottile

asottile May 12, 2019
Member

seems fine to add more context here

maybe something like this?

output.write(
    'Files were modified by this hook.  '
    'Review the changes, `git add`, and repeat the commit.',
)

hmmm, but it's not terribly uncommon for this message to show multiple times with lots of fixers (it's a bit redundant in that case) and now it'll wrap on narrow terminals 🤔

(the change won't be in the staging area, but will need to be added there)

@asottile
Copy link
Member

@asottile asottile commented May 12, 2019

tl;dr I'm on the fence, it seems like a good idea but also seems a little verbose?

@katrinleinweber
Copy link
Author

@katrinleinweber katrinleinweber commented May 14, 2019

True. Would a separate, final message be better, to avoid redundancy in case several files are modified?

@asottile
Copy link
Member

@asottile asottile commented May 14, 2019

True. Would a separate, final message be better, to avoid redundancy in case several files are modified?

Ooh yeah that's a good idea, we already do something similar for --show-diff-on-failure, we'd just need to pass along the "changed files" information somehow.

There's a perf improvement that I've been meaning to make here as well, right now execution looks roughly like this:

- run hook 1
    - diff = git diff
    - run hook
    - diff2 = git diff (compare against diff and report Changed files)
- run hook 2
    - diff = git diff
    - run hook
    - diff2 = git diff (compare against diff and report Changed files)

But it could look like this:

- initial_diff = git diff
- run hook 1 (take initial_diff as a parameter)
    - run hook
    - new_diff = git diff (compare against passed in diff)
   - return the new diff
- run hook 2 (take previous returned diff as a parameter)
    - run hook
    - new_diff = git diff (compare against passed in diff)
   - return the new diff
etc.

with that second patern, it would be easy to compare the initial diff against the last returned diff to see if there was any changes across the whole set of hooks

@asottile
Copy link
Member

@asottile asottile commented Aug 22, 2020

I think the work in #1566 will make this easier to accomplish

@asottile asottile closed this Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.