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

check for long file paths #760

Closed
guykisel opened this issue Apr 25, 2022 · 4 comments
Closed

check for long file paths #760

guykisel opened this issue Apr 25, 2022 · 4 comments

Comments

@guykisel
Copy link
Contributor

guykisel commented Apr 25, 2022

Depending on what you're doing, Windows can have a path length limit of 260 characters. It's kind of complicated and there are a number of workarounds but this limit is true in many cases.

In editions of Windows before Windows 10 version 1607, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit. See Maximum Path Length Limitation for full details.

My proposal is to write a simple hook that checks each path for its length as an absolute path and errors if the path exceeds a configurable value that defaults to 260 chars.

This might make the most sense as part of the Windows illegal filenames check - if so I'm happy to just copy this request into that issue. #589

References

(I did search for dupes and didn't find any similar proposals or requests, but of course if this has come up before and I missed it, please forgive me :) )

@asottile
Copy link
Member

yeah this might be an interesting idea -- I'm not sure how we would pick a good lower bound though (since it kind of depends on where the repository gets cloned to)

it might also be possible just with language: fail and and entry like .{260,} or something? it wouldn't be args configurable but that's perhaps an idea for a repo: local hook?

#589 kinda stalled, not really sure what's up with that and I wouldn't want to tie the two together

@guykisel
Copy link
Contributor Author

guykisel commented Apr 26, 2022

Yeah, for some of the projects I've worked on there's a standardized path recommended for checkouts, like C:/git/your_project, but that is a good point about clone location mattering. In that case maybe if this hook was implemented it would be better to just track path length relative to the repo root, even if that's not a perfect measure of absolute path length.

Using language: fail is a neat option, I didn't even realize it existed! https://pre-commit.com/#fail - link to the docs for anyone else reading this. Something super simple like that does seem like it should work generally.

Somehow in my thinking about this, the clone location issue slipped my mind. Makes me think this might not be quite as generally valuable as I originally thought.

I suppose maybe it could be paired with a hook to warn you if your repo clone location is invalid according to some ruleset, based on length or maybe other rules.

@AFulgens
Copy link

I'm going out on a limb here, but os.getcwd() should return the git repo directory, and then this is a pretty simple python hook. Are PRs welcome for this?

@asottile
Copy link
Member

yeah this might be an interesting idea -- I'm not sure how we would pick a good lower bound though (since it kind of depends on where the repository gets cloned to)

probably not really doable I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants