-
Notifications
You must be signed in to change notification settings - Fork 8.3k
File name extension requirement broke Git hooks #16480
Copy link
Copy link
Open
Labels
KeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeNeeds-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.The behavior reported in the issue is unexpected and needs further investigation.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group
Metadata
Metadata
Assignees
Labels
KeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeNeeds-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.The behavior reported in the issue is unexpected and needs further investigation.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group
Prerequisites
Description
Now that script files must have
.ps1file name extension in Windows, because of #15859, it's no longer possible to have Git hooks written in PowerShell. This is a breaking change!From Git documentation at https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks (emphasis by me)
Git hooks in written in PowerShell have worked flawlessly since the file name exetension requirement was removed in PowerShell 6.x. After the 7.2 release, trying execute a git command that has hooks associated with it results in an error message and commit fails.
Steps to reproduce
Make sure Git is installed with full support for all commands. Meaning that paths
C:\Program Files\Git\cmdC:\Program Files\Git\mingw64\binC:\Program Files\Git\usr\binare present in user or system
PATHenvironment variable. Git for Windows installer will do this for you.Then create a file named
pre-commitwith content:Note that shebang line is required here because of how Git was ported to Windows.
Make sure the file name does not have any extension and place the file into
.git\hooksdirectory of a local git repository.Make some changes in the repo and try to commit them. For example:
git commit -m "Testing"or use VS Code's version control tab.Expected behavior
pre-commit hook gets executed:
Actual behavior
Commit fails with error message:
Git: Processing -File '.git/hooks/pre-commit' failed because the file does not have a '.ps1' extension. Specify a valid PowerShell script file name, and then try again.Error details
No response
Environment data
Visuals
No response