$SoucePath = Read-Host "请输入仓库目录,可空";
$SvnAddress = Read-Host "请输入Svn地址,可空";
$GitAddress = Read-Host "请输入Giv地址,可空";
# 记录当前脚本目录
$pspath=pwd;
if($SvnAddress -eq $null -or $SvnAddress -eq "" -or $GitAddress -eq $null -or $GitAddress -eq "")
{
echo "sync svn to git.";
if($SoucePath -eq $null -or $SoucePath -eq "")
{
throw "[-SoucePath] can not be empty.";
}
# 进入源码目录
pushd $SoucePath;
# 如果 local-git-svn 分支存在才执行这条命令
git branch -d local-git-svn;
# 创建分支并切换到 local-git-svn
git checkout -b local-git-svn refs/remotes/git-svn;
# 拉取SVN最新修改代码
git svn fetch;
# 切换回主分支
git checkout master;
# 再删除分支 local-git-svn
git branch -d local-git-svn;
# 再重写创建分支并切换到 local-git-svn
git checkout -b local-git-svn refs/remotes/git-svn;
# 切换回主分支
git checkout master;
# 合并最新代码到 master 分支
git merge local-git-svn;
# 推送到远程
git push -u origin master;
}
else
{
write-warning "The first time sync svn to git.";
if($SvnAddress -eq $null -or $SvnAddress -eq "")
{
throw "[-SvnAddress] can not be empty.";
}
if($GitAddress -eq $null -or $GitAddress -eq "")
{
throw "[-GitAddress] can not be empty.";
}
# 克隆svn项目
git svn clone $SvnAddress --no-metadata --no-minimize-url --no-minimize-url;
# 添加远程git地址
git remote add origin $GitAddress;
# 提交到git
git push -u origin master -f;
}
# 回到脚本目录
pushd $pspath;
首次将svn转git
& "./svntogit.ps1" -SvnAddress 你的SVN地址 -GitAddress 你的GIT地址
非首次,以后每次同步svn到git
& "./svntogit.ps1" -SoucePath 你的源码目录