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 test -f "$GIT_DIR/branches/origin" ||
12 test -f "$GIT_DIR/remotes/origin" ||
13 die "Where do you want to fetch from?"
17 -a|--a|--ap|--app|--appe|--appen|--append)
23 remote=$(get_remote_url "$@")
26 rsync_slurped_objects=
28 if test "" = "$append"
30 : >$GIT_DIR/FETCH_HEAD
33 append_fetch_head () {
40 # 2.6.11-tree tag would not be happy to be fed to resolve.
41 if git-cat-file commit "$head_" >/dev/null 2>&1
43 head_=$(git-rev-parse --verify "$head_^0") || exit
44 note_="$head_ $remote_name_ from $remote_nick_"
45 echo "$note_" >>$GIT_DIR/FETCH_HEAD
46 echo >&2 "* committish: $note_"
48 echo >&2 "* non-commit: $note_"
50 if test "$local_name_" != ""
52 # We are storing the head locally. Make sure that it is
53 # a fast forward (aka "reverse push").
54 fast_forward_local "$local_name_" "$head_" "$remote_" "$remote_name_"
58 fast_forward_local () {
61 # Tags need not be pointing at commits so there
62 # is no way to guarantee "fast-forward" anyway.
63 echo "$2" >"$GIT_DIR/$1" ;;
65 # NEEDSWORK: use the same cmpxchg protocol here.
66 echo "$2" >"$GIT_DIR/$1.lock"
67 if test -f "$GIT_DIR/$1"
69 local=$(git-rev-parse --verify "$1^0") &&
70 mb=$(git-merge-base "$local" "$2") &&
73 echo >&2 "* $1: same as $4"
77 echo >&2 "* $1: fast forward to $4"
84 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
85 echo >&2 "* $1: does not fast forward to $4"
86 echo >&2 " from $3; leaving it in '$1.remote'"
89 echo >&2 "* $1: storing $4"
92 test -f "$GIT_DIR/$1.lock" &&
93 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
98 for ref in $(get_remote_refs_for_fetch "$@")
102 # These are relative path from $GIT_DIR, typically starting at refs/
104 remote_name=$(expr "$ref" : '\([^:]*\):')
105 local_name=$(expr "$ref" : '[^:]*:\(.*\)')
107 rref="$rref $remote_name"
109 # There are transports that can fetch only one head at a time...
111 http://* | https://*)
112 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
115 head=$(curl -nsf $curl_extra_args "$remote/$remote_name") &&
116 expr "$head" : "$_x40\$" >/dev/null ||
117 die "Failed to fetch $remote_name from $remote"
118 echo Fetching "$remote_name from $remote" using http
119 git-http-pull -v -a "$head" "$remote/" || exit
122 TMP_HEAD="$GIT_DIR/TMP_HEAD"
123 rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
124 head=$(git-rev-parse TMP_HEAD)
126 test "$rsync_slurped_objects" || {
127 rsync -avz --ignore-existing "$remote/objects/" \
128 "$GIT_OBJECT_DIRECTORY/" || exit
129 rsync_slurped_objects=t
133 # We will do git native transport with just one call later.
137 append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
142 http://* | https://* | rsync://* )
143 ;; # we are already done.
145 git-fetch-pack "$remote" $rref |
146 while read sha1 remote_name
158 local_name=$(expr "$found" : '[^:]*:\(.*\)')
159 append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"