Make fetch/pull scripts terminate cleanly on errors
[git] / git-fetch-script
1 #!/bin/sh
2 #
3 merge_repo=$1
4 merge_name=${2:-HEAD}
5
6 : ${GIT_DIR=.git}
7 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
8
9 download_one () {
10         # remote_path="$1" local_file="$2"
11         case "$1" in
12         http://*)
13                 wget -q -O "$2" "$1" ;;
14         /*)
15                 test -f "$1" && cat >"$2" "$1" ;;
16         *)
17                 rsync -L "$1" "$2" ;;
18         esac
19 }
20
21 download_objects () {
22         # remote_repo="$1" head_sha1="$2"
23         case "$1" in
24         http://*)
25                 git-http-pull -a "$2" "$1/"
26                 ;;
27         /*)
28                 git-local-pull -l -a "$2" "$1/"
29                 ;;
30         *)
31                 rsync -avz --ignore-existing \
32                         "$1/objects/." "$GIT_OBJECT_DIRECTORY"/.
33                 ;;
34         esac
35 }
36
37 echo "Getting remote $merge_name"
38 download_one "$merge_repo/$merge_name" "$GIT_DIR"/MERGE_HEAD || exit 1
39
40 echo "Getting object database"
41 download_objects "$merge_repo" "$(cat "$GIT_DIR"/MERGE_HEAD)" || exit 1