pre-commit-hooks icon indicating copy to clipboard operation
pre-commit-hooks copied to clipboard

Add check for illegal Windows filenames

Open ericfrederich opened this issue 4 years ago • 9 comments

There are file and directory names which are legal in Git and most operating systems but illegal in Windows. They should be avoided in case a developer happens to use Windows.

The following names are illegal as bare names as well as with extensions regardless of case for files or directories. For instance CoM6, cOm6.txt, com6.foo.jpg, etc are all illegal. Windows will refuse to create those files if you try to check them out.

From: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Do not use the following reserved names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended. For more information, see Namespaces.

ericfrederich avatar Apr 22 '21 12:04 ericfrederich

seems like a good idea in line with the spirit of the repository! 👍

asottile avatar Apr 24 '21 01:04 asottile

i would suggest splitting the check between Win32 and WinNT, even if WinObj does a good job

theGASK avatar May 12 '21 12:05 theGASK

@theGASK sorry what?

asottile avatar May 12 '21 14:05 asottile

Any progress on this?

tspearconquest avatar Jan 29 '22 17:01 tspearconquest

Just needs to be merged. It's a new standalone check. My opinion should even make it into the default sample config.

ericfrederich avatar Jan 29 '22 21:01 ericfrederich

Just needs to be merged

the PR has a bunch of un-addressed feedback

asottile avatar Jan 29 '22 22:01 asottile

@asottile Would you want somebody to pick up the PR you already reviewed or prefer if somebody worked on the language: fail solution you suggested there?

DanielNoord avatar May 23 '22 19:05 DanielNoord

the original author seems to not be interested in fixing their PR so yeah I would appreciate a new one -- probably just language: fail since it'll be simpler and faster

asottile avatar May 23 '22 19:05 asottile

+1 on this :) I would also suggest checking for characters which cannot be used on windows, such as :.

By the way this is a problem in WSL which has led to a lot of pain for me in the past. One contributor had committed a file:Zone.Identifier file which is generated due to downloaded files from the web (see https://github.com/microsoft/WSL/issues/4609). This was a HUGE pain to remove as it broke the repository on Windows. I would even suggest explicitly checking for that sort of file, but a hook checking for bad characters such as : would help.

jleclanche avatar Dec 11 '22 11:12 jleclanche