【问题标题】:hg commands in powershell hook from tortoisehg来自tortoisehg的powershell钩子中的hg命令
【发布时间】:2013-03-23 18:13:10
【问题描述】:

我创建了一个 powershell 脚本作为提交挂钩运行,以将用户名写入文件。我在powershell中用来提取用户名的命令是:

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

其中 $repodir 是存储库的目录。当我从 powershell 命令行提交时,钩子会根据需要执行提取用户名。当我从 tortoisehg 工作台中提交时,钩子会执行(我可以在输出文件中看到更改)但 $hguser 中没有信息,其他 hg 命令也没有影响。从 tortoisehg 中执行 hg 是否需要特殊语法,它是否在正确的路径中执行?

【问题讨论】:

  • $repodir 设置在哪里?
  • 我编辑了原始问题以显示它的设置位置

标签: powershell mercurial tortoisehg mercurial-hook


【解决方案1】:

它似乎对我有用。

.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 通过 TortoiseHg/hg.exe 提交填充。使用 TortoiseHg 2.7。

【讨论】:

  • 那行得通。我将研究为什么它在 powershell 中而不是 tortoisehg 中工作。谢谢!
  • grep 是 powershell 别名还是外部程序?它不是内置别名,所以如果它是自定义别名可能意味着您的 powershell 配置文件不会通过 TortoiseHg 加载,或者如果它是外部程序,则可能意味着它不在 TortoiseHg 的路径中。
  • 对,就是这样,TortoiseHg加载的profile没有grep。如果它调用缺少的函数,我预计它的退出值会很差。
猜你喜欢
  • 1970-01-01
  • 2012-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多