Question

I created a powershell script to run as a commit hook to write the username to a file. The command I am using in powershell to extract the username is:

$repodir = "C:\Users\Administrator\Documents\Visual Studio 2012\Projects\testRepo"
cd $repodir
$hguser = hg --cwd $repodir tip | grep user

where $repodir is the directory of the repository. When I commit from the powershell command line the hook executes an extracts the username as desired. When I commit from within tortoisehg workbench the hook executes (I can see changes in my output file) but there is no information in $hguser, other hg commands also have no affect. Is there special syntax needed to execute hg from within tortoisehg, is it executing in the correct path?

Was it helpful?

Solution

It appears to work for me.

.hg/hgrc

[hooks]
commit = powershell.exe -File "C:\users\andy\desktop\test\test.ps1"

test.ps1

$repodir = "C:\Users\andy\Desktop\Test"
cd $repodir
$hguser = (hg tip) | ? {$_ -match '^user:\s+([\w\s]+\w)'} | % {$matches[1]}
$hguser | Out-File user.txt -Encoding ASCII

user.txt is populated via TortoiseHg/hg.exe commit. Using TortoiseHg 2.7.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top