$SoucePath = Read-Host "請輸入倉庫目錄,可空";
$firstTimeDir = Read-Host "請輸入項目名稱,可空";
$SvnAddress = Read-Host "請輸入Svn地址,可空";
$GitAddress = Read-Host "請輸入Git地址,可空";
# 記錄當前腳本目錄
$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 -f;
}
else
{
write-warning "The first time sync svn to git.";
if($firstTimeDir -eq $null -or $firstTimeDir -eq "")
{
throw "[-firstTimeDir] can not be empty.";
}
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 $firstTimeDir;
pushd "./$firstTimeDir";
git init;
# 添加遠程git地址
git remote add origin $GitAddress;
# 提交到git
git push -u origin master -f;
}
# 回到腳本目錄
pushd $pspath;
首次將svn轉git
& "./svntogit.ps1"