├── .gitignore ├── README.md ├── config.txt ├── source.txt ├── transfer.py └── transfer.sh /.gitignore: -------------------------------------------------------------------------------- 1 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # svn-git-transfer SVN仓库批量迁移Git工具 2 | 3 | 用于批量将 SVN 仓库迁移到 Git 的工具。 4 | 5 | ## 依赖 6 | 7 | * git-svn 8 | 9 | ## 使用方法 10 | 11 | * 在 Gitlab 上建立目的迁移仓库。 12 | * 编写 source.txt ,格式为: 13 | 14 | ``` 15 | [原SVN路径]>[目标Git仓库地址] 16 | ``` 17 | 18 | 支持批量迁移多个路径,每一行都保持以上格式即可。 19 | 20 | * 修改 config.txt ,改为你自己的用户名和邮箱。 21 | * 执行工具: 22 | 23 | ``` sh 24 | $ python transfer.py 25 | ``` 26 | 27 | 完成后将会有如下的结果展示: 28 | 29 | ``` 30 | 迁移结束,共成功迁移3个路径,失败迁移1个路径 31 | 失败路径1:http://yourcompany.com/svn/your_repo/trunk/master/android/cardbox 32 | ``` 33 | 34 | 然后自行解决迁移失败的路径即可。 35 | -------------------------------------------------------------------------------- /config.txt: -------------------------------------------------------------------------------- 1 | USER_NAME=yourname 2 | USER_EMAIL=youremail@gmail.com 3 | -------------------------------------------------------------------------------- /source.txt: -------------------------------------------------------------------------------- 1 | http://yourcompany.com/svn/your_repo/trunk/master/android/>http://yourcompany.com/gitlab/your_repo/android.git 2 | -------------------------------------------------------------------------------- /transfer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | import io,os,sys,time,string,subprocess 4 | 5 | reload(sys) 6 | sys.setdefaultencoding('utf8') 7 | 8 | success_list = [] 9 | fail_list = [] 10 | with open("source.txt") as f: 11 | while True: 12 | a_line = f.readline() 13 | if (a_line == ""): 14 | break 15 | if (a_line.find('>') > 0): 16 | source, target = a_line.split('>') 17 | source = source.strip() 18 | target = target.strip() 19 | if (source.endswith('/')): 20 | source = source[:-1] 21 | pos=source.rfind("/") 22 | name=source[pos+1:] 23 | print("source:" + source) 24 | print("target:" + target) 25 | print("name:" + name) 26 | if (source == ""): 27 | print("原SVN路径为空,迁移失败!请检查source.txt内容是否正确!") 28 | continue 29 | if (target == ""): 30 | print("目标仓库路径为空,迁移失败!请检查source.txt内容是否正确!") 31 | fail_list.append(source) 32 | continue 33 | res = subprocess.call(["sh", "transfer.sh", source, target, name]) 34 | if (res != 0): 35 | fail_list.append(source) 36 | else: 37 | success_list.append(source) 38 | 39 | print("迁移结束,共成功迁移%d个路径,失败迁移%d个路径" % (len(success_list), len(fail_list))) 40 | if (len(fail_list) > 0): 41 | i = 1 42 | for source in fail_list: 43 | print("失败路径%d:%s" % (i, source)) 44 | i = i+1 45 | -------------------------------------------------------------------------------- /transfer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if test $# -ne 3 3 | then 4 | echo "Need 3 Arguments." 5 | exit 1 6 | fi 7 | 8 | source ./config.txt 9 | 10 | SOURCE=$1 11 | TARGET=$2 12 | NAME=$3 13 | 14 | git svn clone ${SOURCE} --no-metadata ${NAME} 15 | if test $? -eq 0 16 | then 17 | cd ${NAME} 18 | git config user.name ${USER_NAME} 19 | git config user.email ${USER_EMAIL} 20 | git remote add gitlab ${TARGET} 21 | git push -u gitlab master 22 | if test $? -eq 0 23 | then 24 | echo "${TARGET} 提交成功!" 25 | exit 0 26 | else 27 | echo "${TARGET} 提交失败!" 28 | exit 1 29 | fi 30 | cd - 31 | else 32 | echo "${SOURCE} 克隆失败!" 33 | exit 1 34 | fi 35 | --------------------------------------------------------------------------------