傻瓜式同步svn到git

$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"
posted @ 2020-07-16 14:35  百小僧  阅读(1342)  评论(0编辑  收藏  举报