I am using Git on Windows and trying to include unit testing in the workflow. If the commit message contain a keyword. The commit-msg hook will trigger Powershell command to run some Nunit tests.
This is my ruby code in the hook
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
puts "The commit message is " + message
$regex = /(#runtest)/
if $regex.match(message)
exec 'powershell.exe -ExecutionPolicy RemoteSigned -Command {RunNunitTestCase}'
end
However when I commit a changes, the result is like below. The exec line was run but do nothing.
PS D:\testfolder> git commit -am '#runtest'
The commit message is #runtest
[authorupdate b14878d] 123
1 files changed, 1 insertions(+), 0 deletions(-)
I am new to ruby and powershell. Feel free to comment if this workflow is feasible or you have a better approach.
Thank you.