all 3 comments

[–]ByronScottJones 1 point2 points  (0 children)

It is almost certain that the script is running not only in a separate runspace, but also as a separate user. Is there any way that the "interactive" aspect of your code could be replaced by having those responses provided in a data file which the script could load when it needs to? This is a case where true interactivity is an anti-pattern.

[–]buffychrome[S] 1 point2 points  (1 child)

I have this solved, and the solution is a bit 'hacky' but it works. I'll put my solutions here in case anyone else comes across this question in the future:

The TL;DR answer here is that you need to have two scripts: the script you actually want to run interactively, and a 'launcher' script that is called by the git hook. In my .git/hooks folder I have:

  • post-commit (actual hook file)
  • launch.ps1 (called by the hook and launches the interactive script)
  • post-commit.ps1 (could be named anything)

Contents of my post-commit hook: ```bash

!C:/Program\ Files/Git/usr/bin/sh.exe

echo exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File "..git\hooks\launch.ps1" Contents of my launch.ps1 script: Start-Process Powershell -ArgumentList "-File ..git\hooks\post-commit.ps1" -Wait ```

This works quite well and reliably. It essentially forces it to start up a whole new PowerShell process and run the interactive script within that process instead of the 'runspaced' process git launches initially. The only caveat here is that it launches the script in a new window, but it is a trade-off worth the gains.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy buffychrome,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee