4 USAGE
='<fetch-options> <repository> <refspec>...'
7 set_reflog_action
"fetch $*"
9 TOP
=$
(git-rev-parse
--show-cdup)
15 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
16 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
32 while case "$#" in 0) break ;; esac
35 -a|
--a|
--ap|
--app|
--appe|
--appen|
--append)
38 --upl|
--uplo|
--uploa|
--upload|
--upload-|
--upload-p|\
39 --upload-pa|
--upload-pac|
--upload-pack)
44 -f|
--f|
--fo|
--for|
--forc|
--force)
47 -t|
--t|
--ta|
--tag|
--tags)
50 -n|
--n|
--no|
--no-|
--no-t|
--no-ta|
--no-tag|
--no-tags)
53 -u|
--u|
--up|
--upd|
--upda|
--updat|
--update|
--update-|
--update-h|\
54 --update-he|
--update-hea|
--update-head|
--update-head-|\
55 --update-head-o|
--update-head-ok)
61 -k|
--k|
--ke|
--kee|
--keep)
65 shallow_depth
="--depth=`expr "z
$1" : 'z-[^=]*=\(.*\)'`"
69 shallow_depth
="--depth=$1"
83 origin
=$
(get_default_remote
)
84 test -n "$(get_remote_url ${origin})" ||
85 die
"Where do you want to fetch from today?"
86 set x
$origin ; shift ;;
90 remote
=$
(get_remote_url
"$@")
93 rsync_slurped_objects
=
95 if test "" = "$append"
97 : >"$GIT_DIR/FETCH_HEAD"
100 # Global that is reused later
101 ls_remote_result
=$
(git ls-remote
$upload_pack "$remote") ||
102 die
"Cannot get the repository state from $remote"
104 append_fetch_head
() {
111 t
) not_for_merge_
='not-for-merge' ;;
112 '') not_for_merge_
= ;;
115 # remote-nick is the URL given on the command line (or a shorthand)
116 # remote-name is the $GIT_DIR relative refs/ path we computed
119 # the $note_ variable will be fed to git-fmt-merge-msg for further
121 case "$remote_name_" in
125 note_
="$(expr "$remote_name_" : 'refs/heads/\(.*\)')"
126 note_
="branch '$note_' of " ;;
128 note_
="$(expr "$remote_name_" : 'refs/tags/\(.*\)')"
129 note_
="tag '$note_' of " ;;
131 note_
="$(expr "$remote_name_" : 'refs/remotes/\(.*\)')"
132 note_
="remote branch '$note_' of " ;;
134 note_
="$remote_name of " ;;
136 remote_1_
=$
(expr "z$remote_" : 'z\(.*\)\.git/*$') &&
138 note_
="$note_$remote_"
140 # 2.6.11-tree tag would not be happy to be fed to resolve.
141 if git-cat-file commit
"$head_" >/dev
/null
2>&1
143 headc_
=$
(git-rev-parse
--verify "$head_^0") ||
exit
144 echo "$headc_ $not_for_merge_ $note_" >>"$GIT_DIR/FETCH_HEAD"
146 echo "$head_ not-for-merge $note_" >>"$GIT_DIR/FETCH_HEAD"
149 update_local_ref
"$local_name_" "$head_" "$note_"
152 update_local_ref
() {
153 # If we are storing the head locally make sure that it is
154 # a fast forward (aka "reverse push").
156 label_
=$
(git-cat-file
-t $2)
157 newshort_
=$
(git-rev-parse
--short $2)
158 if test -z "$1" ; then
159 [ "$verbose" ] && echo >&2 "* fetched $3"
160 [ "$verbose" ] && echo >&2 " $label_: $newshort_"
163 oldshort_
=$
(git show-ref
--hash --abbrev "$1" 2>/dev
/null
)
167 # Tags need not be pointing at commits so there
168 # is no way to guarantee "fast-forward" anyway.
169 if test -n "$oldshort_"
171 if now_
=$
(git show-ref
--hash "$1") && test "$now_" = "$2"
173 [ "$verbose" ] && echo >&2 "* $1: same as $3"
174 [ "$verbose" ] && echo >&2 " $label_: $newshort_" ||
:
176 echo >&2 "* $1: updating with $3"
177 echo >&2 " $label_: $newshort_"
178 git-update-ref
-m "$GIT_REFLOG_ACTION: updating tag" "$1" "$2"
181 echo >&2 "* $1: storing $3"
182 echo >&2 " $label_: $newshort_"
183 git-update-ref
-m "$GIT_REFLOG_ACTION: storing tag" "$1" "$2"
187 refs
/heads
/* | refs
/remotes
/*)
188 # $1 is the ref being updated.
189 # $2 is the new value for the ref.
190 local=$
(git-rev-parse
--verify "$1^0" 2>/dev
/null
)
193 # Require fast-forward.
194 mb
=$
(git-merge-base
"$local" "$2") &&
197 if test -n "$verbose"
199 echo >&2 "* $1: same as $3"
200 echo >&2 " $label_: $newshort_"
204 echo >&2 "* $1: fast forward to $3"
205 echo >&2 " old..new: $oldshort_..$newshort_"
206 git-update-ref
-m "$GIT_REFLOG_ACTION: fast-forward" "$1" "$2" "$local"
212 case ",$force,$single_force," in
214 echo >&2 "* $1: forcing update to non-fast forward $3"
215 echo >&2 " old...new: $oldshort_...$newshort_"
216 git-update-ref
-m "$GIT_REFLOG_ACTION: forced-update" "$1" "$2" "$local"
219 echo >&2 "* $1: not updating to non-fast forward $3"
220 echo >&2 " old...new: $oldshort_...$newshort_"
226 echo >&2 "* $1: storing $3"
227 echo >&2 " $label_: $newshort_"
228 git-update-ref
-m "$GIT_REFLOG_ACTION: storing head" "$1" "$2"
234 # updating the current HEAD with git-fetch in a bare
235 # repository is always fine.
236 if test -z "$update_head_ok" && test $
(is_bare_repository
) = false
238 orig_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
241 # If --tags (and later --heads or --all) is specified, then we are
242 # not talking about defaults stored in Pull: line of remotes or
243 # branches file, and just fetch those and refspecs explicitly given.
244 # Otherwise we do what we always did.
246 reflist
=$
(get_remote_refs_for_fetch
"$@")
250 echo "$ls_remote_result" |
262 if git-check-ref-format "$name"
264 echo ".${name}:${name}"
266 echo >&2 "warning: tag ${name} ignored"
271 # remote URL plus explicit refspecs; we need to merge them.
272 reflist
="$reflist$LF$taglist"
274 # No explicit refspecs; fetch tags only.
288 # These are relative path from $GIT_DIR, typically starting at refs/
290 if expr "z$ref" : 'z\.' >/dev
/null
293 ref
=$
(expr "z$ref" : 'z\.\(.*\)')
297 if expr "z$ref" : 'z+' >/dev
/null
300 ref
=$
(expr "z$ref" : 'z+\(.*\)')
304 remote_name
=$
(expr "z$ref" : 'z\([^:]*\):')
305 local_name
=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
307 rref
="$rref$LF$remote_name"
309 # There are transports that can fetch only one head at a time...
311 http
://* | https
://* |
ftp://*)
312 test -n "$shallow_depth" &&
313 die
"shallow clone with http not supported"
314 proto
=`expr "$remote" : '\([^:]*\):'`
315 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
318 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
319 "`git-repo-config --bool http.noEPSV`" = true
]; then
320 noepsv_opt
="--disable-epsv"
323 # Find $remote_name from ls-remote output.
326 echo "$ls_remote_result" |
329 test "z$name" = "z$remote_name" ||
continue
334 expr "z$head" : "z$_x40\$" >/dev
/null ||
335 die
"No such ref $remote_name at $remote"
336 echo >&2 "Fetching $remote_name from $remote using $proto"
337 git-http-fetch
-v -a "$head" "$remote/" ||
exit
340 test -n "$shallow_depth" &&
341 die
"shallow clone with rsync not supported"
342 TMP_HEAD
="$GIT_DIR/TMP_HEAD"
343 rsync
-L -q "$remote/$remote_name" "$TMP_HEAD" ||
exit 1
344 head=$
(git-rev-parse
--verify TMP_HEAD
)
346 test "$rsync_slurped_objects" ||
{
347 rsync
-av --ignore-existing --exclude info \
348 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" ||
exit
350 # Look at objects/info/alternates for rsync -- http will
351 # support it natively and git native ones will do it on
352 # the remote end. Not having that file is not a crime.
353 rsync
-q "$remote/objects/info/alternates" \
354 "$GIT_DIR/TMP_ALT" 2>/dev
/null ||
355 rm -f "$GIT_DIR/TMP_ALT"
356 if test -f "$GIT_DIR/TMP_ALT"
358 resolve_alternates
"$remote" <"$GIT_DIR/TMP_ALT" |
361 case "$alt" in 'bad alternate: '*) die
"$alt";; esac
362 echo >&2 "Getting alternate: $alt"
363 rsync
-av --ignore-existing --exclude info \
364 "$alt" "$GIT_OBJECT_DIRECTORY/" ||
exit
366 rm -f "$GIT_DIR/TMP_ALT"
368 rsync_slurped_objects
=t
372 # We will do git native transport with just one call later.
376 append_fetch_head
"$head" "$remote" \
377 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" ||
exit
382 http
://* | https
://* |
ftp://* | rsync
://* )
383 ;; # we are already done.
385 ( : subshell because we muck with IFS
388 git-fetch-pack
--thin $exec $keep $shallow_depth "$remote" $rref ||
389 echo failed
"$remote"
393 if test -n "$keepfile" && test -f "$keepfile"
400 while read sha1 remote_name
404 echo >&2 "Fetch failure: $remote"
406 # special line coming from index-pack with the pack name
410 keepfile
="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
438 local_name
=$
(expr "z$found" : 'z[^:]*:\(.*\)')
439 append_fetch_head
"$sha1" "$remote" \
440 "$remote_name" "$remote_nick" "$local_name" \
441 "$not_for_merge" ||
exit
449 fetch_main
"$reflist" ||
exit
451 # automated tag following
452 case "$no_tags$tags" in
456 # effective only when we are following remote branch
457 # using local tracking branch.
459 echo "$ls_remote_result" |
460 git-show-ref
--exclude-existing=refs
/tags
/ |
463 git-cat-file
-t "$sha1" >/dev
/null
2>&1 ||
continue
464 echo >&2 "Auto-following $name"
465 echo ".${name}:${name}"
471 # do not deepen a shallow tree when following tags
473 fetch_main
"$taglist" ||
exit ;;
477 # If the original head was empty (i.e. no "master" yet), or
478 # if we were told not to worry, we do not have to check.
483 curr_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
484 if test "$curr_head" != "$orig_head"
487 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
489 die
"Cannot fetch into the current branch."