-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClone-repo.sh
executable file
·58 lines (48 loc) · 1.7 KB
/
Clone-repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
###################################################################################
# clone-repo.sh
# Clone the specific repository/s
#
# Usage: Clone-repo.sh <config_file> <out_dir>
# 1) Read the to-be-exported repository from $config_file;
# 2) Clone the repositories to $out_dir
# For example:
# ../git-backup/clone-repo.sh /tmp/repo-branch-config.txt /tmp
#
# 20180227:XJS : Initial
###################################################################################
configName=$1
outputTopDirectory=$2
# the exact output directory should be
orgName='mne' #works for mne organization only so far
#################################
# Capture the org & repo from $configName file,
repoList=`grep -Ev "^$|^[#;]" $configName |awk -F " " '{ print $1 }'|sort -u`
cd $outputTopDirectory
git init
preFix=`date +%Y-%m-%d`
outputTopDirectory=$outputTopDirectory/$preFix
if [ ! -d $outputTopDirectory ]; then
mkdir -p $outputTopDirectory
fi
pwdName=`pwd`
for repoName in `echo $repoList`
do
cd $pwdName
if [ ! -d $outputTopDirectory/$orgName ]; then #make the directory for Organization if missing
mkdir -p $outputTopDirectory/$orgName
fi
cd $outputTopDirectory/$orgName
outputDirectory="${outputTopDirectory}/${orgName}/${repoName}"
if [ -d $outputDirectory ]; then #remove the directory for repository if existing
rm -rf $outputDirectory
fi
git clone https://github.ibm.com/${orgName}/${repoName}.git #clone with https
if [ $? != 0 ];then
echo "Failed to clone repository of:${orgName}/${repoName}"
else
echo "Success to clone repository of:${orgName}/${repoName}"
fi
done
# end of program
#################################