Fork me on GitHub

通过Shell脚本将VSS项目批量创建并且提交迁移至Gitlab

脚本运行环境:Git Bash

系统环境:Windows 10 Pro 1709

VSS版本:Microsoft Visual SourceSafe 2005

 

我的VSS工作目录结构如下:

D:\work\

  --vss

  ----project1

  ------src

  ------README.md

  ------ ......

  ----project2

  ------doc

  ------src

  ------README.md

  ------ ......

  ----project3

  ------ ......

 

脚本代码:

 1 #!/bin/bash
 2 
 3 git config --global user.name "Allen"
 4 git config --global user.email allen@domain.com
 5 
 6 # Init params
 7 namespace=VssProjects # Group Name
 8 namespaceId=10 # Group Id
 9 rootPath=/d/work/vss # VSS work path
10 index=0
11 folderList=[]
12 
13 # Each folders
14 cd $rootPath
15 for i in $(ls $rootPath)
16 do
17   echo $index $i
18   folderList[index]=$i
19   index=`expr $index + 1`
20 done
21 
22 # Print folders length
23 echo ${#folderList[@]}
24 
25 # Git Init
26 for dirName in ${folderList[*]}
27 do
28   workPath=$rootPath/$dirName #项目工作目录
29   projectName=$dirName # 项目名称
30   data='{"name":"replacement","visibility":"private","namespace_id":namespaceId,"path":"replacement"}' # 待提交的JSON数据
31   postData=${data//replacement/$projectName} # 全部替换
32   postData=${data/namespaceId/$namespaceId} # 只替换一次
33   echo $postData
34   
35   # Gitlab Create Projects
36   curl --header "Private-Token: your private token" \
37   -H "Accept: application/json" \
38   -H "Content-type: application/json" \
39   -X POST \
40   -d $postData \
41   http://git.domain.com/api/v4/projects
42   
43   # Git repository init & push
44   cd $workPath
45   git init
46   git remote add origin http://username:password@domain.com/$namespace/$projectName.git
47   touch README.md
48   git add README.md
49   git add .
50   git commit -m "Init version"
51   git push -u origin master
52 done

 

posted @ 2017-11-24 23:56  VAllen  阅读(1139)  评论(0编辑  收藏  举报