我有以下脚本,该脚本从文件加载凭据并使用凭据嵌入的URL格式提取。
$remote = "http://server/repo.git"
$credential = Import-CliXml -Path 'gitcreds.xml'
Write-Host "Using credentials for $($credential.UserName)"
$url = $remote
$url = $url.Replace("http://","http://$($credential.UserName):$($credential.GetNetworkCredential().Password)@")
$url = $url.Replace("https://","https://$($credential.UserName):$($credential.GetNetworkCredential().Password)@")
Write-Host "Pulling from $($url)..."
git pull $url -f -q --progress --recurse-submodules
我正在使用它来生成凭证文件:
$credname = Read-Host "Name for the credential file? (include .xml)"
$credential = Get-Credential
$credential | Export-CliXml -Path $credname
输出更新后的$url
的调试行看起来与我期望的(Pulling from http://gituser:password@server/repo.git...
)完全一样,但是我仍然收到Windows凭据提示。为什么会发生,如何避免呢?