-
Notifications
You must be signed in to change notification settings - Fork 2
/
rgit.sh
73 lines (65 loc) · 1.49 KB
/
rgit.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
DEPTH_RECORD_FILE=.resumable_git_depth
OUT_FILE=rgit.out
if [ 0 -eq $# ]
then
depth=`cat ${DEPTH_RECORD_FILE}`
if [ "" == $depth ]
then
echo "can not find resume record in current dir"
exit 1
fi
elif [ 1 -eq $# ]
then
echo "now clone the 1st layer"
clone_str=`git clone --depth 1 $1 2>&1|grep Cloning`
[[ "$clone_str" =~ \'(.*)\' ]] && work_dir=${BASH_REMATCH[1]}
if [[ "$work_dir" == "" ]]
then
echo "fail to clone"
exit 1
fi
cd $work_dir
depth=2
fi
step=1
done_time=0
while true
do
echo ${depth} > $DEPTH_RECORD_FILE
echo "fetch depth $depth"
git fetch --depth $depth --progress 2>$OUT_FILE
if [ 0 -eq $? ]
then
step=$depth
depth=`expr $depth + $depth`
else
depth=`expr $depth - $step / 2`
step=`expr $step / 2`
if [ 0 -eq $step ]
then
step=1
fi
fi
cat $OUT_FILE | grep "remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0"
if [ 0 -eq $? ]
then
## should move 2 times over
echo 'maybe fetch over'
if [ 2 -eq $done_time ]
then
echo 'fetch over'
break
else
done_time=`expr $done_time + 1`
fi
else
done_time=0
fi
done
# finally , fetch branches
echo 'now fetch branches'
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"; git fetch origin
echo 'done ^_^'
rm $OUT_FILE
rm $DEPTH_RECORD_FILE