2

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?

kieferm
  • 23
  • 4

1 Answers1

2

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.

Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
  • That worked. I'll look into why it was working from within powershell but not tortoisehg. Thanks! – kieferm Mar 24 '13 at 13:26
  • Is grep a powershell alias or is it an external program? It's not a built in alias, so if it's a custom alias is might mean your powershell profile doesn't load through TortoiseHg, or if it's an external program it might mean it's not in the path in TortoiseHg. – Andy Arismendi Mar 24 '13 at 16:24
  • Yes, that is it, the profile that TortoiseHg loads does not have grep. I expected it to have a bad exit value if it called a missing function. – kieferm Mar 25 '13 at 12:19