-
Notifications
You must be signed in to change notification settings - Fork 394
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
[PRECOMMIT] Better UX for handling of edge cases for pre-commit hook #780
Comments
Hi @Skylion007 👋 , thanks for discussing this! Sure I agree that is an area where we could improve the logic. Before we go to that let me mention that in some areas of the program (i.e. the contents manager) we do have a tolerance for these timestamps that might not be in the right order, and a tolerance of 1 second is allowed on timestamp: Lines 135 to 141 in ee468c8
In the context of the Lines 940 to 948 in ee468c8
I think it should be feasible to add an intermediate case and use the git commit order when all the member of the pair are unchanged from git HEAD, but come from different commits. Do you think you could propose a PR for that? |
Hello @Skylion007 , I have prepared a PR which implements something that sounds like what you suggest (and passes all the test). Would you like to give an eye to #796? Also I'd be more confident if we could add a test that reproduces the issue documented above. Let me come back to you with a short proposal... |
What I can propose is 1e1b2e5: jupytext/tests/test_pre_commit_mode.py Lines 213 to 254 in 1e1b2e5
That test fails on |
* New function git_timestamp that returns the commit timestamp * Reproduce #780 with a test * The commit time is available as a Unix timestamp with %ct
I've been using the pre-commit JuPyText and found an issue with our current strategy. Currently, we use whichever source file has the more recent timestamp to determine which file should be updated. However, while this works well locally, it can cause issues later. We have a pre-commit install that runs as part of the CircleCI check. Each time the CI is run, the repo is freshly cloned. The expected behavior is that if only one of the two paired files is updated, it should suggest updating the "older" file to the more recently committed file. However, the git clone has freshly cloned each file and our git hook currently relies on timestamps. The notebook has been cloned later in the process than the Python file, therefore the timestamp is newer. Therefore, the older notebook tries to update the more recent script instead of the other way around producing an incorrect diff: the broken pre-commit run can be found here:
https://app.circleci.com/pipelines/github/facebookresearch/habitat-lab/1630/workflows/d81b2754-6461-45d1-bc95-634e82752119/jobs/3793
The expected behavior is that if one file is from a more recent commit, that one should be updated. There will be ambiguity when two incorrect files are from the same commit, but this is when we may be able to fallback from utime.
Solution: We should use the following tree to decide which file to update:
The text was updated successfully, but these errors were encountered: