#Enable powershell script.
Set-ExecutionPolicy RemoteSigned
#Add environment variables temperally.
$env:path+=";C:\Program Files\SlikSvn\bin";
$env:path+=";C:\Windows\System32";
$env:path+=";C:\WINDOWS\system32\windowspowershell\v1.0";
#Define the path of TFS project, SVN project and redirect temp file.
$tfsFolder="C:\project\tfs";
$svnFolder="C:\project\svn";
$tempFolder="C:\";
#Get the latest code forcely from TFS server.
tf get $tfsFolder /force /recursive;
#Update the code from SVN server.
svn update $svnFolder;
svn cleanup $svnFolder;
#Compare the two folders of TFS project and SVN project. Redirect the result to a temp .txt file.
tf folderdiff $tfsFolder $svnFolder /recursive /noprompt /view:targetonly > $tempFolder\targetonly.txt
tf folderdiff $tfsFolder $svnFolder /recursive /noprompt /view:sourceonly > $tempFolder\sourceonly.txt
#Copy the specific files from TFS project to SVN project by filter.
xcopy $tfsFolder\*.java $svnFolder /s/e /y
xcopy $tfsFolder\*.xml $svnFolder /s/e /y
xcopy $tfsFolder\*.properties $svnFolder /s/e /y
#Read the difference redirected previously, SVN delete the missing files(except .svn info).
For ($file = [system.io.file]::OpenText("$tempFolder\targetonly.txt");
!($file.EndOfStream); $line = $file.ReadLine())
{
if($line.IndexOf(".svn").Equals(-1) -and ($line.IndexOf("\") -gt 0) -and ($line.IndexOf("Items That Exist Only in").Equals(-1)))
{
$line;
svn delete $line ;
}
}
$file.close()
#Read the difference redirected previously, SVN add the added files(except .svn info).
For ($file = [system.io.file]::OpenText("$tempFolder\sourceonly.txt");
!($file.EndOfStream); $line = $file.ReadLine())
{
if(($line.IndexOf("\") -gt 0) -and ($line.IndexOf("Items That Exist Only in").Equals(-1)))
{
$addFile = $line.Remove(0,$tfsFolder.Length).Insert(0,$svnFolder);
$addFile;
svn add $addFile;
}
}
$file.close()
#SVN commit.
svn commit -m"commit" $svnFolder;
用poweshell从TFS获取最新代码,并提交到SVN服务器上
最新推荐文章于 2020-03-26 14:41:31 发布
本文介绍如何通过PowerShell脚本从TFS获取最新代码,并将其更新到SVN服务器。首先设置环境变量,然后分别获取TFS和SVN的最新代码。接着比较两个项目文件夹的差异,将TFS中的特定文件复制到SVN,并删除或添加SVN中缺失或新增的文件。最后,提交SVN的更改。
1113

被折叠的 条评论
为什么被折叠?



