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"
10 while case "$#" in 0) break ;; esac
13 -a|--a|--ap|--app|--appe|--appen|--append)
17 -f|--f|--fo|--for|--forc|--force)
29 test -f "$GIT_DIR/branches/origin" ||
30 test -f "$GIT_DIR/remotes/origin" ||
31 die "Where do you want to fetch from?"
36 remote=$(get_remote_url "$@")
39 rsync_slurped_objects=
41 if test "" = "$append"
43 : >$GIT_DIR/FETCH_HEAD
46 append_fetch_head () {
53 # 2.6.11-tree tag would not be happy to be fed to resolve.
54 if git-cat-file commit "$head_" >/dev/null 2>&1
56 headc_=$(git-rev-parse --verify "$head_^0") || exit
57 note_="$headc_ $remote_name_ from $remote_nick_"
58 echo "$note_" >>$GIT_DIR/FETCH_HEAD
59 echo >&2 "* committish: $note_"
61 echo >&2 "* non-commit: $note_"
63 if test "$local_name_" != ""
65 # We are storing the head locally. Make sure that it is
66 # a fast forward (aka "reverse push").
67 fast_forward_local "$local_name_" "$head_" "$remote_" "$remote_name_"
71 fast_forward_local () {
74 # Tags need not be pointing at commits so there
75 # is no way to guarantee "fast-forward" anyway.
76 if test -f "$GIT_DIR/$1"
78 echo >&2 "* $1: updating with $4"
81 echo >&2 "* $1: storing $4"
84 echo "$2" >"$GIT_DIR/$1" ;;
87 # NEEDSWORK: use the same cmpxchg protocol here.
88 echo "$2" >"$GIT_DIR/$1.lock"
89 if test -f "$GIT_DIR/$1"
91 local=$(git-rev-parse --verify "$1^0") &&
92 mb=$(git-merge-base "$local" "$2") &&
95 echo >&2 "* $1: same as $4"
99 echo >&2 "* $1: fast forward to $4"
106 echo >&2 "* $1: does not fast forward to $4"
107 case "$force,$single_force" in
109 echo >&2 " from $3; forcing update."
112 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
113 echo >&2 " from $3; leaving it in '$1.remote'"
118 echo >&2 "* $1: storing $4"
121 test -f "$GIT_DIR/$1.lock" &&
122 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
127 for ref in $(get_remote_refs_for_fetch "$@")
131 # These are relative path from $GIT_DIR, typically starting at refs/
133 if expr "$ref" : '\+' >/dev/null
136 ref=$(expr "$ref" : '\+\(.*\)')
140 remote_name=$(expr "$ref" : '\([^:]*\):')
141 local_name=$(expr "$ref" : '[^:]*:\(.*\)')
143 rref="$rref $remote_name"
145 # There are transports that can fetch only one head at a time...
147 http://* | https://*)
148 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
151 head=$(curl -nsf $curl_extra_args "$remote/$remote_name") &&
152 expr "$head" : "$_x40\$" >/dev/null ||
153 die "Failed to fetch $remote_name from $remote"
154 echo Fetching "$remote_name from $remote" using http
155 git-http-pull -v -a "$head" "$remote/" || exit
158 TMP_HEAD="$GIT_DIR/TMP_HEAD"
159 rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
160 head=$(git-rev-parse TMP_HEAD)
162 test "$rsync_slurped_objects" || {
163 rsync -avz --ignore-existing "$remote/objects/" \
164 "$GIT_OBJECT_DIRECTORY/" || exit
165 rsync_slurped_objects=t
169 # We will do git native transport with just one call later.
173 append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
178 http://* | https://* | rsync://* )
179 ;; # we are already done.
181 git-fetch-pack "$remote" $rref |
182 while read sha1 remote_name
199 local_name=$(expr "$found" : '[^:]*:\(.*\)')
200 append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"