summaryrefslogtreecommitdiff
path: root/git-fetch-script
blob: fb4a53776ac0f3f5d95e4c4b6a68ab0b3913974c (plain)
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/sh
#
destination=FETCH_HEAD
 
merge_repo=$1
merge_name=${2:-HEAD}
if [ "$2" = "tag" ]; then
	merge_name="refs/tags/$3"
	destination="$merge_name"
fi
 
: ${GIT_DIR=.git}
: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
 
download_one () {
	# remote_path="$1" local_file="$2"
	case "$1" in
	http://*)
		wget -q -O "$2" "$1" ;;
	/*)
		test -f "$1" && cat >"$2" "$1" ;;
	*)
		rsync -L "$1" "$2" ;;
	esac
}
 
download_objects () {
	# remote_repo="$1" head_sha1="$2"
	case "$1" in
	http://*)
		git-http-pull -a "$2" "$1/"
		;;
	/*)
		git-local-pull -l -a "$2" "$1/"
		;;
	*)
		rsync -avz --ignore-existing \
			"$1/objects/." "$GIT_OBJECT_DIRECTORY"/.
		;;
	esac
}
 
echo "Getting remote $merge_name"
download_one "$merge_repo/$merge_name" "$GIT_DIR/$destination" || exit 1
 
echo "Getting object database"
download_objects "$merge_repo" "$(cat "$GIT_DIR/$destination")" || exit 1