0

I installed git 2.28.0 on windows. In fact, i can't find post-checkout.sample hook in the hooks repository under /.git repository. Is post-checkout.sample hook supported on windows ? When i installed the same version of git on linux i found the post-checkout.sample hook. I even tried with the git 2.23.0 version and i had the same problem. hooks on windows

I tried to create post-checkout that print a simple message "hello". But it doesn't work. However when I copied this file in pre-commit it works. Any suggestions?

K.cyrine
  • 158
  • 1
  • 1
  • 9

2 Answers2

0

I never saw a post-checkout.sample in mingw64/share/git-core/templates/hooks/ of a Git For Windows distribution.

But that hook should work, provided you make it:

  • a file named "post-checkout"
  • a bash script (see an example here)
  • in your repo/.git/hooks folder

There was actually a proposal (RFC) for a post-checkout.sample in 2009, but it was not picked up at the time.

The question was asked (also in 2009):

I also noticed that the post-checkout sample does not exist when I init a new archive. Is this a bug?

No, it's security.
Hooks are executable files and shouldn't blindly be copied around for security reasons.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

It seems that it doesn't work on an empty repository. I just committed a file in my repository and when i excute git checkout -b new_branch, the post-checkout hook worked.

K.cyrine
  • 158
  • 1
  • 1
  • 9
  • Good point. It should work also when you checkout a file. – VonC Sep 01 '20 at 07:19
  • Strange: https://stackoverflow.com/q/44427458/6309 show it should work. I just tested it by making a `myrepo/.git/hooks/post-checkout` file, and the checked out just one file (even though it wasn't even modified!): It worked. – VonC Sep 01 '20 at 11:38