#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;