-
Notifications
You must be signed in to change notification settings - Fork 29
/
mirror
executable file
·47 lines (39 loc) · 1.31 KB
/
mirror
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
#!/bin/bash
set -x
set -e
OTHER="$1"
if ! [ -d "$OTHER" ] ; then
echo usage: $0 {existing git checkout dir}
exit 1
else
pushd "$OTHER" > /dev/null
OTHER="$(pwd)"
popd > /dev/null
fi
# Basedir configuration
BASEDIR="$(dirname $0)"
cd "$BASEDIR"
BASEDIR="$(pwd)"
MIRROR="$BASEDIR/mirror.git"
if ! [ -e "$MIRROR" ] ; then
git init --bare "$MIRROR"
fi
function mirror_repo() {
URL="$1"
REPONAME="$2"
git --git-dir "$MIRROR" config --unset remote.${REPONAME}.uri || true
git --git-dir "$MIRROR" config remote.${REPONAME}.url "$URL"
git --git-dir "$MIRROR" config --unset remote.${REPONAME}.fetch || true
git --git-dir "$MIRROR" config --add remote.${REPONAME}.fetch "+refs/heads/*:refs/heads/${REPONAME}/*"
git --git-dir "$MIRROR" config --add remote.${REPONAME}.fetch "+refs/tags/*:refs/tags/${REPONAME}/*"
git --git-dir "$MIRROR" config remote.${REPONAME}.tagopt "--no-tag"
git --git-dir "$MIRROR" fetch "$REPONAME"
}
for gitdir in $(find "$OTHER" -name .git) ; do
OTHER_URL="$(git --git-dir "$gitdir" config remote.origin.url)"
REPONAME="$(basename -s .git "$OTHER_URL")"
mirror_repo "$gitdir" "$REPONAME"
mirror_repo "$OTHER_URL" "$REPONAME"
done
mirror_repo "https://github.com/ironsteel/iconv-android.git" "iconv"
git --git-dir "$MIRROR" gc --aggressive