3 . git-sh-setup-script || die "Not a git archive"
4 . git-parse-remote-script
5 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
6 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
11 die "Where do you want to fetch from?" ;;
14 -a|--a|--ap|--app|--appe|--appen|--append)
20 remote=$(get_remote_url "$@")
23 rsync_slurped_objects=
25 if test "" = "$append"
27 : >$GIT_DIR/FETCH_HEAD
30 append_fetch_head () {
37 # 2.6.11-tree tag would not be happy to be fed to resolve.
38 if git-cat-file commit "$head_" >/dev/null 2>&1
40 head_=$(git-rev-parse --verify "$head_^0") || exit
41 note_="$head_ $remote_name_ from $remote_nick_"
42 echo "$note_" >>$GIT_DIR/FETCH_HEAD
43 echo >&2 "* committish: $note_"
45 echo >&2 "* non-commit: $note_"
47 if test "$local_name_" != ""
49 # We are storing the head locally. Make sure that it is
50 # a fast forward (aka "reverse push").
51 fast_forward_local "$local_name_" "$head_" "$remote_" "$remote_name_"
55 fast_forward_local () {
58 # Tags need not be pointing at commits so there
59 # is no way to guarantee "fast-forward" anyway.
60 echo "$2" >"$GIT_DIR/$1" ;;
62 # NEEDSWORK: use the same cmpxchg protocol here.
63 echo "$2" >"$GIT_DIR/$1.lock"
64 if test -f "$GIT_DIR/$1"
66 local=$(git-rev-parse --verify "$1^0") &&
67 mb=$(git-merge-base "$local" "$2") &&
70 echo >&2 "* $1: same as $4"
74 echo >&2 "* $1: fast forward to $4"
81 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
82 echo >&2 "* $1: does not fast forward to $4"
83 echo >&2 " from $3; leaving it in '$1.remote'"
86 echo >&2 "* $1: storing $4"
89 test -f "$GIT_DIR/$1.lock" &&
90 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
95 for ref in $(get_remote_refs_for_fetch "$@")
99 # These are relative path from $GIT_DIR, typically starting at refs/
101 remote_name=$(expr "$ref" : '\([^:]*\):')
102 local_name=$(expr "$ref" : '[^:]*:\(.*\)')
104 rref="$rref $remote_name"
106 # There are transports that can fetch only one head at a time...
108 http://* | https://*)
109 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
112 head=$(curl -nsf $curl_extra_args "$remote/$remote_name") &&
113 expr "$head" : "$_x40\$" >/dev/null ||
114 die "Failed to fetch $remote_name from $remote"
115 echo Fetching "$remote_name from $remote" using http
116 git-http-pull -v -a "$head" "$remote/" || exit
119 TMP_HEAD="$GIT_DIR/TMP_HEAD"
120 rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
121 head=$(git-rev-parse TMP_HEAD)
123 test "$rsync_slurped_objects" || {
124 rsync -avz --ignore-existing "$remote/objects/" \
125 "$GIT_OBJECT_DIRECTORY/" || exit
126 rsync_slurped_objects=t
130 # We will do git native transport with just one call later.
134 append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
139 http://* | https://* | rsync://* )
140 ;; # we are already done.
142 git-fetch-pack "$remote" $rref |
143 while read sha1 remote_name
155 local_name=$(expr "$found" : '[^:]*:\(.*\)')
156 append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"