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 while case "$#" in 0) break ;; esac
14 -a|
--a|
--ap|
--app|
--appe|
--appen|
--append)
17 -f|
--f|
--fo|
--for|
--forc|
--force)
20 -u|
--u|
--up|
--upd|
--upda|
--updat|
--update|
--update-|
--update-h|\
21 --update-he|
--update-hea|
--update-head|
--update-head-|\
22 --update-head-o|
--update-head-ok)
34 test -f "$GIT_DIR/branches/origin" ||
35 test -f "$GIT_DIR/remotes/origin" ||
36 die
"Where do you want to fetch from today?"
41 remote
=$
(get_remote_url
"$@")
44 rsync_slurped_objects
=
46 if test "" = "$append"
48 : >$GIT_DIR/FETCH_HEAD
51 append_fetch_head
() {
58 # remote-nick is the URL given on the command line (or a shorthand)
59 # remote-name is the $GIT_DIR relative refs/ path we computed
61 case "$remote_name_" in
65 note_
="$(expr "$remote_name_" : 'refs/heads/\(.*\)')"
66 note_
="branch '$note_' of " ;;
68 note_
="$(expr "$remote_name_" : 'refs/tags/\(.*\)')"
69 note_
="tag '$note_' of " ;;
71 note_
="$remote_name of " ;;
73 remote_1_
=$
(expr "$remote_" : '\(.*\)\.git/*$') &&
75 note_
="$note_$remote_"
77 # 2.6.11-tree tag would not be happy to be fed to resolve.
78 if git-cat-file commit
"$head_" >/dev
/null
2>&1
80 headc_
=$
(git-rev-parse
--verify "$head_^0") ||
exit
81 echo "$headc_ $note_" >>$GIT_DIR/FETCH_HEAD
82 echo >&2 "* committish: $head_"
85 echo >&2 "* non-commit: $head_"
88 if test "$local_name_" != ""
90 # We are storing the head locally. Make sure that it is
91 # a fast forward (aka "reverse push").
92 fast_forward_local
"$local_name_" "$head_" "$note_"
96 fast_forward_local
() {
99 # Tags need not be pointing at commits so there
100 # is no way to guarantee "fast-forward" anyway.
101 if test -f "$GIT_DIR/$1"
103 echo >&2 "* $1: updating with $3"
105 echo >&2 "* $1: storing $3"
107 echo "$2" >"$GIT_DIR/$1" ;;
110 # NEEDSWORK: use the same cmpxchg protocol here.
111 echo "$2" >"$GIT_DIR/$1.lock"
112 if test -f "$GIT_DIR/$1"
114 local=$
(git-rev-parse
--verify "$1^0") &&
115 mb
=$
(git-merge-base
"$local" "$2") &&
118 echo >&2 "* $1: same as $3"
121 echo >&2 "* $1: fast forward to $3"
127 echo >&2 "* $1: does not fast forward to $3;"
128 case "$force,$single_force" in
130 echo >&2 " forcing update."
133 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
134 echo >&2 " leaving it in '$1.remote'"
139 echo >&2 "* $1: storing $3"
141 test -f "$GIT_DIR/$1.lock" &&
142 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
147 case "$update_head_ok" in
149 orig_head
=$
(cat "$GIT_DIR/HEAD" 2>/dev
/null
)
153 for ref
in $
(get_remote_refs_for_fetch
"$@")
157 # These are relative path from $GIT_DIR, typically starting at refs/
159 if expr "$ref" : '\+' >/dev
/null
162 ref
=$
(expr "$ref" : '\+\(.*\)')
166 remote_name
=$
(expr "$ref" : '\([^:]*\):')
167 local_name
=$
(expr "$ref" : '[^:]*:\(.*\)')
169 rref
="$rref $remote_name"
171 # There are transports that can fetch only one head at a time...
173 http
://* | https
://*)
174 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
177 head=$
(curl
-nsf $curl_extra_args "$remote/$remote_name") &&
178 expr "$head" : "$_x40\$" >/dev
/null ||
179 die
"Failed to fetch $remote_name from $remote"
180 echo Fetching
"$remote_name from $remote" using http
181 git-http-pull
-v -a "$head" "$remote/" ||
exit
184 TMP_HEAD
="$GIT_DIR/TMP_HEAD"
185 rsync
-L "$remote/$remote_name" "$TMP_HEAD" ||
exit 1
186 head=$
(git-rev-parse TMP_HEAD
)
188 test "$rsync_slurped_objects" ||
{
189 rsync
-avz --ignore-existing "$remote/objects/" \
190 "$GIT_OBJECT_DIRECTORY/" ||
exit
191 rsync_slurped_objects
=t
195 # We will do git native transport with just one call later.
199 append_fetch_head
"$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
204 http
://* | https
://* | rsync
://* )
205 ;; # we are already done.
207 git-fetch-pack
"$remote" $rref |
208 while read sha1 remote_name
225 local_name
=$
(expr "$found" : '[^:]*:\(.*\)')
226 append_fetch_head
"$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
231 # If the original head was empty (i.e. no "master" yet), or
232 # if we were told not to worry, we do not have to check.
233 case ",$update_head_ok,$orig_head," in
237 curr_head
=$
(cat "$GIT_DIR/HEAD" 2>/dev
/null
)
238 if test "$curr_head" != "$orig_head"
240 echo "$orig_head" >$GIT_DIR/HEAD
241 die
"Cannot fetch into the current branch."