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

Improve pre commit hook #17595

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Improve pre commit hook #17595

merged 3 commits into from
Dec 17, 2024

Conversation

Arthur-Milchior
Copy link
Member

@Arthur-Milchior Arthur-Milchior commented Dec 12, 2024

I expect first commit to be sufficient. Commit three is probably overkill. But I don't want to lose hours of work anymore. And the slight risk that, if we stop overwritting the same file all the time, we save data seems quite nicer than risking a repeat.

Fixed: #17591

The documentation state that the function should return, but actually
it exists. This is repaired.

Removing `set -e` ensure the script does not stop if the linter fails.
This is probably what we expected given that we put the return value
in a variable.

This would ensure that the patch that was saved is always restored.

I don't expect this to cause issues because the remaining of the
changes are not destructive.

I manually tested that the bug can't be reproduced with this
script. However, I've not tested the change in case of `git apply`
failure, as I don't know how to force apply to fail.

Fixed: ankidroid#17593
The variable meaning was not clear. It seemed to indicate it was
actually the diff.
This ensures that, in case we have an issue and restore does not work,
a future `git commit` don't overwrite the patch file.
@david-allison
Copy link
Member

How does this code differ from the currently generated hook?

Can a subset of this be submitted upstream?

@Arthur-Milchior
Copy link
Member Author

The base of the bug is that we had set -e. That's not part of the code that is marked as copied from upstream.
It cause the code to halt when the lint fails, and so the restore of the patch is never done.

Patch 2 by itself there is no reason to just ask them to rename a variable.

Patch 3 may be nice. But honestly, I added just for extra safety. When their code work as expected (i.e. we have not added set -e beforehand) there is no need for it. Also, even without set -e, even if applying the patch fail, finding the patch and applying may not be easy for most users who are not used to go in a hidden folder, open a file that is not known by android studio and apply a patch. That's really a last resort save if everything else fails

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to approve. LGTM!

@david-allison david-allison added the Needs Second Approval Has one approval, one more approval to merge label Dec 13, 2024
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, my condolences for the last work that triggered this - hadn't commented on that but have seen the comments going around. What a pain

@mikehardy mikehardy added this pull request to the merge queue Dec 17, 2024
@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Dec 17, 2024
Merged via the queue into ankidroid:main with commit 8e8c53b Dec 17, 2024
9 checks passed
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Dec 17, 2024
@github-actions github-actions bot added this to the 2.21 release milestone Dec 17, 2024
@Arthur-Milchior Arthur-Milchior deleted the pre-commit branch December 25, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants