Reputation: 825
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:
--
#!/bin/sh
c:/windows/system32/WindowsPowerShell/v1.0/PowerShell.exe -Command "New-Item File.txt -type file"
--
Any help, thoughts? I don't know TCL, so I couldn't really understand how GitGui was calling hooks.
Upvotes: 3
Views: 2148
Reputation: 2191
I tried out the steps to reproduce and get the same result. Changing the powershell path to /c/... did nothing, but I was able to get the PowerShell script to be called by using the start
command. Looking at the file for start (C:\Program Files (x86)\Git\bin\start
on my system), it seems to simply be wrapping the call with the following:
cmd //c start "$@"
I've tried several variations, but cannot for the life of me seem to get a PowerShell script to run as well as return output (any console/error messages or an exit code).
Long story short, if you're just needing to make sure the script is ran you can use:
start PowerShell.exe [params]
If anyone has ideas on how to get output and an exit code, I'd love to hear it.
Upvotes: 1
Reputation: 7638
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:
c:/windows/system32/WindowsPowerShell/v1.0/PowerShell.exe -ExecutionPolicy:Bypass -Command "New-Item File.txt -type file"
Upvotes: 0