-
Notifications
You must be signed in to change notification settings - Fork 12
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
File selection for check-file-format.sh
seems over-broad and potentially misconfigured
#129
Comments
Prior to this patch, the `git diff` command used to identify which files to check for editorconfig compliance caught too many files, and did the expensive part of the check inside the per-file loop. By lucky chance, the editorconfig-checker container image has a `git` binary installed, so we can move the entire loop inside a single container invocation. Fixes #129.
On further reflection, I think there's another problem lurking here. We're using |
Thanks @regularfry for reporting this issue. With regard to comparing changes to the The command
selects all the staged files and modified files in the working tree. The last part of it, What causes the slowness of this script is that a docker container is spun up for each file that has to be checked. Running the |
I think, introducing the mode switch/parameter is a good suggestion. Let's make it simple - I like your original suggestion of using git from within the container. We should do that. Implementing this approach simplifies the check execution since passing filenames from outside the container might not be as trivial as it seems, especially when considering challenges like handling and escaping spaces in file names. Here are the modes I envision being implemented:
Subsequently, the git precommit hook will execute |
Prior to this patch, the `git diff` command used to identify which files to check for editorconfig compliance caught too many files, and did the expensive part of the check inside the per-file loop. By lucky chance, the editorconfig-checker container image has a `git` binary installed, so we can move the entire loop inside a single container invocation. Fixes #129.
<!-- markdownlint-disable-next-line first-line-heading --> ## Description Prior to this patch, the `git diff` command used to identify which files to check for editorconfig compliance caught too many files, and did the expensive part of the check inside the per-file loop. By lucky chance, the editorconfig-checker container image has a `git` binary installed, so we can move the entire loop inside a single container invocation. Fixes #129. ## Context It makes the editorconfig check, which is called in a pre-commit hook, fast. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [ ] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [x] Bug fix (non-breaking change which fixes an issue)
Here we run a diff to see what files we need to check against
editorconfig
to make sure everything's aligned.However there are two problems. The first is that this is a script we run in a pre-commit hook, but it checks all files changed since the divergence with the
origin/main
branch. That means we run it repeatedly on any file we've ever changed on our current branch, not just the changes we're trying to commit. That the script callsdocker run...
once per file that's ever changed in a loop makes this slow for even fairly short histories, especially if the upstream has had merges from others since we branched.The second problem is that it assumes
origin/main
points at something controlled. In my current checkout,origin
points at a fork, and thenhs-england-tools/repository-template
repo is calledupstream
. In my case, it should be comparing toupstream/main
. This makes it worse because inevitably my fork is behind, so it adds more files to the changed list.I think this should just be calling
git diff --name-only
without the branch comparison. If it's getting called in every git commit, there's no sense in re-checking all the files changed in the branch. We only need to check what's changed in this commit specifically.The text was updated successfully, but these errors were encountered: