2040c125f92c32a4590a895fb321dbd37e7a49d1
[git/git.git] / git-fetch-script
1 #!/bin/sh
2 #
3 . git-sh-setup-script || die "Not a git archive"
4 . git-parse-remote "$@"
5 merge_repo="$_remote_repo"
6 merge_head="$_remote_head"
7 merge_store="$_remote_store"
8
9 TMP_HEAD="$GIT_DIR/TMP_HEAD"
10
11 case "$merge_repo" in
12 http://* | https://*)
13 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
14 curl_extra_args="-k"
15 fi
16 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' &&
17 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" &&
18 head=$(curl -ns $curl_extra_args "$merge_repo/$merge_head") &&
19 expr "$head" : "$_x40\$" >/dev/null || {
20 echo >&2 "Failed to fetch $merge_head from $merge_repo"
21 exit 1
22 }
23 git-fetch-dumb-http "$head" "$@"
24 case "$?" in
25 0) ;;
26 2) no_dumb_http_support=1 ;;
27 *) exit;;
28 esac
29 echo Fetching "$merge_head" using http
30 git-http-pull -v -a "$head" "$merge_repo/" || {
31 case "$no_dumb_http_support" in
32 1)
33 echo >&2 "* This could be because the $merge_repo is packed without"
34 echo >&2 " preparing dumb server support files."
35 ;;
36 esac
37 exit 1
38 }
39 ;;
40 rsync://*)
41 rsync -L "$merge_repo/$merge_head" "$TMP_HEAD" || exit 1
42 head=$(git-rev-parse TMP_HEAD)
43 rm -f "$TMP_HEAD"
44 rsync -avz --ignore-existing "$merge_repo/objects/" "$GIT_OBJECT_DIRECTORY/"
45 ;;
46 *)
47 head=$(git-fetch-pack "$merge_repo" "$merge_head")
48 ;;
49 esac || exit 1
50
51 git-rev-parse --verify "$head" > /dev/null || exit 1
52
53 case "$merge_store" in
54 '')
55 ;;
56 *)
57 echo "$head" > "$GIT_DIR/$merge_store"
58 esac &&
59
60 # FETCH_HEAD is fed to git-resolve-script which will eventually be
61 # passed to git-commit-tree as one of the parents. Make sure we do
62 # not give a tag object ID.
63
64 git-rev-parse "$head^0" >"$GIT_DIR/FETCH_HEAD"