【发布时间】:2011-07-20 20:33:55
【问题描述】:
我在 Mercurial 存储库的根目录中运行以下命令。我想删除所有以“.hg”开头的文件和文件夹:
gci -rec -filter ".hg*" | remove-item -recurse -force
奇怪的是,它确实有效,但仍然产生以下异常:
Get-ChildItem : Could not find a part of the path 'C:\temp\WSCopyTest\MyCompany.Services.DaftPunk\.hg\'.
At line:1 char:4
+ gci <<<< -rec -filter ".hg*" | remove-item -recurse -force
+ CategoryInfo : ReadError: (C:\temp\WSCopyT...es.DaftPunk\.hg:String) [Get-ChildItem], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
由于Get-ChildItem 引发了异常,我怀疑我对 PowerShell 中流水线的理解存在缺陷。就像Get-ChildItem 找到一个项目,将其传递给管道中的下一个 cmdlet,然后查找下一个?是这样的吗?
以下应该是复制问题的脚本,但在同一台机器上,它可以完美运行:
$repoRoot = "C:\Temp\HgDeleteTest\MyRepo"
remove-item $repoRoot -recurse -force
md $repoRoot
pushd $repoRoot
hg.exe init
add-content ShouldBeLeftBehind.txt "This is some text in a file that should be left behind once the various .hg files/directories are removed."
add-content .hgignore syntax:glob
add-content .hgignore *.dll
add-content .hgignore *.exe
hg.exe commit --addremove --message "Building test repository with one commit."
gci -rec -filter ".hg*" | remove-item -recurse -force
popd
【问题讨论】:
-
同样的问题在一台机器上工作,但我在另一台机器上得到这个错误。
-
我怀疑如果有 2 组行为可能是 powershell 版本问题。
标签: powershell mercurial