-
Notifications
You must be signed in to change notification settings - Fork 1
/
repoclone
executable file
·64 lines (57 loc) · 1.96 KB
/
repoclone
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
#!/bin/bash
#
# repoclone
# version 0.2
#
# Clones a local Android repo to another local Android repo, with native git clone object hardlinks to conserve storage.
#
# Copyright 2012 Warren Togami <[email protected]>
# Licensed under the GNU GPL v3+.
errorexit() {
echo "ERROR: You must invoke this command with two parameters."
echo
echo " $0 <fromrepo> <torepo>"
echo
echo " * <fromrepo> must be in the current directory."
echo " * <torepo> must be in the current directory, but you can move it later."
echo " * <torepo> MUST NOT EXIST."
echo " * Neither names should have a trailing slash."
exit 255
}
# Sanity Checks
# TODO: Make this more flexible in dealing with relative or full pathnames
[ -z "$1" ] || [ -z "$2" ] && errorexit
[ "$1" != $(basename $1) ] || [ "$2" != $(basename $2) ] && errorexit
[ -e "$2" ] && echo "ERROR: $2 already exists." && exit 255
# Abort immediately if any error occurs
set -e
# Copy directory structure without .git directories
echo "### Copy directory structure without .git directories ###"
echo mkdir $2/
echo rsync -a -f"+ */" -f"- *" $1/.repo/ $2/.repo/
mkdir $2/
rsync -a -f"+ */" -f"- *" $1/.repo/ $2/.repo/
# Copy .repo without pack/ directories
echo "### Copy .repo without pack/ directories ###"
echo rsync -a -f"- pack/" $1/.repo/ $2/.repo/
rsync -a -f"- pack/" $1/.repo/ $2/.repo/
# Hardlink copy git pack/ objects
echo "### Hardlink copy git pack/ objects ###"
for packdir in $(find $1/.repo/ -type d -name pack); do
targetdir=$(echo $packdir |sed "s/^$1/$2/;s/pack$//")
echo cp -al $packdir $targetdir
cp -al $packdir $targetdir
done
# Done
echo
echo "Done cloning $1 to $2!"
echo
echo "Suggested Next Steps"
echo "===================="
echo " cd $2"
echo " repo init -b ics"
echo " # Switch to a different branch."
echo " # You should first adjust your .repo/local_manifest.xml"
echo " repo sync"
echo " # Restore checkout of working directories from .repo"
echo