I'm seeing some strange stuff in how Git GUI and TortoiseGit call Git hooks. Given the following post-checkout hook, one would expect git to execute the powershell command and create the file:
#!/bin/sh
c:/windows/system32/WindowsPowerShell/v1.0/PowerShell.exe -Command "New-Item File.txt -type file"
If I run this hook using the Git Bash, the file is created in my repository. If I run this hook using Atalassian's SourceTree, I also get the file. The hook starts to act strange when calling a checkout from either TortoiseGit or GitGui. Neither produce the file.
I have been able to get the hook (bash) to call a simple exe that I created. The problem seems to be with powershell or how i'm invoking powershell. I have tried to call powershell with -Sta, -ExecutionPolicy RemoteSigned and -NoProfile, but nothing seems to work in Git Gui or TortoiseGit.
The big surprise for me was the hook not working correctly with GitGui. Does anyone know what could be causing this?
How to reproduce:
- Running on Win7
- Have Git-Gui Version 0.17.GITGUI
- Have Git Version 1.8.3.msysgit.0
- Init a new repo
- Create a file in the new repo under .git/hooks called post-checkout
- Put the following script in the newly created post-checkout hook:
--
#!/bin/sh
c:/windows/system32/WindowsPowerShell/v1.0/PowerShell.exe -Command "New-Item File.txt -type file"
--
- Add/commit any file to your new repo
- run git checkout master in your new repo using git bash
- Look for a file named File.txt (Confirms that git bash is calling powershell correctly)
- Delete the new file
- Open GitGui or TortoiseGit in the same repo and run a checkout on master
- Look for the file called File.txt (Won't exist)
Any help, thoughts? I don't know TCL, so I couldn't really understand how GitGui was calling hooks.
I think I saw this happen once before. The ExecutionPolicy is different when in an interactive shell vs a shell spawned by a script. Try this: