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"
31 while case "$#" in 0) break ;; esac
34 -a|
--a|
--ap|
--app|
--appe|
--appen|
--append)
37 --upl|
--uplo|
--uploa|
--upload|
--upload-|
--upload-p|\
38 --upload-pa|
--upload-pac|
--upload-pack)
43 -f|
--f|
--fo|
--for|
--forc|
--force)
46 -t|
--t|
--ta|
--tag|
--tags)
49 -n|
--n|
--no|
--no-|
--no-t|
--no-ta|
--no-tag|
--no-tags)
52 -u|
--u|
--up|
--upd|
--upda|
--updat|
--update|
--update-|
--update-h|\
53 --update-he|
--update-hea|
--update-head|
--update-head-|\
54 --update-head-o|
--update-head-ok)
60 -k|
--k|
--ke|
--kee|
--keep)
75 origin
=$
(get_default_remote
)
76 test -n "$(get_remote_url ${origin})" ||
77 die
"Where do you want to fetch from today?"
78 set x
$origin ; shift ;;
82 remote
=$
(get_remote_url
"$@")
85 rsync_slurped_objects
=
87 if test "" = "$append"
89 : >"$GIT_DIR/FETCH_HEAD"
92 # Global that is reused later
93 ls_remote_result
=$
(git ls-remote
$upload_pack "$remote") ||
94 die
"Cannot get the repository state from $remote"
96 append_fetch_head
() {
103 t
) not_for_merge_
='not-for-merge' ;;
104 '') not_for_merge_
= ;;
107 # remote-nick is the URL given on the command line (or a shorthand)
108 # remote-name is the $GIT_DIR relative refs/ path we computed
111 # the $note_ variable will be fed to git-fmt-merge-msg for further
113 case "$remote_name_" in
117 note_
="$(expr "$remote_name_" : 'refs/heads/\(.*\)')"
118 note_
="branch '$note_' of " ;;
120 note_
="$(expr "$remote_name_" : 'refs/tags/\(.*\)')"
121 note_
="tag '$note_' of " ;;
123 note_
="$(expr "$remote_name_" : 'refs/remotes/\(.*\)')"
124 note_
="remote branch '$note_' of " ;;
126 note_
="$remote_name of " ;;
128 remote_1_
=$
(expr "z$remote_" : 'z\(.*\)\.git/*$') &&
130 note_
="$note_$remote_"
132 # 2.6.11-tree tag would not be happy to be fed to resolve.
133 if git-cat-file commit
"$head_" >/dev
/null
2>&1
135 headc_
=$
(git-rev-parse
--verify "$head_^0") ||
exit
136 echo "$headc_ $not_for_merge_ $note_" >>"$GIT_DIR/FETCH_HEAD"
138 echo "$head_ not-for-merge $note_" >>"$GIT_DIR/FETCH_HEAD"
141 update_local_ref
"$local_name_" "$head_" "$note_"
144 update_local_ref
() {
145 # If we are storing the head locally make sure that it is
146 # a fast forward (aka "reverse push").
148 label_
=$
(git-cat-file
-t $2)
149 newshort_
=$
(git-rev-parse
--short $2)
150 if test -z "$1" ; then
151 [ "$verbose" ] && echo >&2 "* fetched $3"
152 [ "$verbose" ] && echo >&2 " $label_: $newshort_"
155 oldshort_
=$
(git show-ref
--hash --abbrev "$1" 2>/dev
/null
)
159 # Tags need not be pointing at commits so there
160 # is no way to guarantee "fast-forward" anyway.
161 if test -n "$oldshort_"
163 if now_
=$
(git show-ref
--hash "$1") && test "$now_" = "$2"
165 [ "$verbose" ] && echo >&2 "* $1: same as $3"
166 [ "$verbose" ] && echo >&2 " $label_: $newshort_" ||
:
168 echo >&2 "* $1: updating with $3"
169 echo >&2 " $label_: $newshort_"
170 git-update-ref
-m "$GIT_REFLOG_ACTION: updating tag" "$1" "$2"
173 echo >&2 "* $1: storing $3"
174 echo >&2 " $label_: $newshort_"
175 git-update-ref
-m "$GIT_REFLOG_ACTION: storing tag" "$1" "$2"
179 refs
/heads
/* | refs
/remotes
/*)
180 # $1 is the ref being updated.
181 # $2 is the new value for the ref.
182 local=$
(git-rev-parse
--verify "$1^0" 2>/dev
/null
)
185 # Require fast-forward.
186 mb
=$
(git-merge-base
"$local" "$2") &&
189 if test -n "$verbose"
191 echo >&2 "* $1: same as $3"
192 echo >&2 " $label_: $newshort_"
196 echo >&2 "* $1: fast forward to $3"
197 echo >&2 " old..new: $oldshort_..$newshort_"
198 git-update-ref
-m "$GIT_REFLOG_ACTION: fast-forward" "$1" "$2" "$local"
204 case ",$force,$single_force," in
206 echo >&2 "* $1: forcing update to non-fast forward $3"
207 echo >&2 " old...new: $oldshort_...$newshort_"
208 git-update-ref
-m "$GIT_REFLOG_ACTION: forced-update" "$1" "$2" "$local"
211 echo >&2 "* $1: not updating to non-fast forward $3"
212 echo >&2 " old...new: $oldshort_...$newshort_"
218 echo >&2 "* $1: storing $3"
219 echo >&2 " $label_: $newshort_"
220 git-update-ref
-m "$GIT_REFLOG_ACTION: storing head" "$1" "$2"
226 case "$update_head_ok" in
228 orig_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
232 # If --tags (and later --heads or --all) is specified, then we are
233 # not talking about defaults stored in Pull: line of remotes or
234 # branches file, and just fetch those and refspecs explicitly given.
235 # Otherwise we do what we always did.
237 reflist
=$
(get_remote_refs_for_fetch
"$@")
241 echo "$ls_remote_result" |
253 if git-check-ref-format "$name"
255 echo ".${name}:${name}"
257 echo >&2 "warning: tag ${name} ignored"
262 # remote URL plus explicit refspecs; we need to merge them.
263 reflist
="$reflist$LF$taglist"
265 # No explicit refspecs; fetch tags only.
279 # These are relative path from $GIT_DIR, typically starting at refs/
281 if expr "z$ref" : 'z\.' >/dev
/null
284 ref
=$
(expr "z$ref" : 'z\.\(.*\)')
288 if expr "z$ref" : 'z+' >/dev
/null
291 ref
=$
(expr "z$ref" : 'z+\(.*\)')
295 remote_name
=$
(expr "z$ref" : 'z\([^:]*\):')
296 local_name
=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
298 rref
="$rref$LF$remote_name"
300 # There are transports that can fetch only one head at a time...
302 http
://* | https
://* |
ftp://*)
303 proto
=`expr "$remote" : '\([^:]*\):'`
304 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
307 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
308 "`git-repo-config --bool http.noEPSV`" = true
]; then
309 noepsv_opt
="--disable-epsv"
312 # Find $remote_name from ls-remote output.
315 echo "$ls_remote_result" |
318 test "z$name" = "z$remote_name" ||
continue
323 expr "z$head" : "z$_x40\$" >/dev
/null ||
324 die
"No such ref $remote_name at $remote"
325 echo >&2 "Fetching $remote_name from $remote using $proto"
326 git-http-fetch
-v -a "$head" "$remote/" ||
exit
329 TMP_HEAD
="$GIT_DIR/TMP_HEAD"
330 rsync
-L -q "$remote/$remote_name" "$TMP_HEAD" ||
exit 1
331 head=$
(git-rev-parse
--verify TMP_HEAD
)
333 test "$rsync_slurped_objects" ||
{
334 rsync
-av --ignore-existing --exclude info \
335 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" ||
exit
337 # Look at objects/info/alternates for rsync -- http will
338 # support it natively and git native ones will do it on
339 # the remote end. Not having that file is not a crime.
340 rsync
-q "$remote/objects/info/alternates" \
341 "$GIT_DIR/TMP_ALT" 2>/dev
/null ||
342 rm -f "$GIT_DIR/TMP_ALT"
343 if test -f "$GIT_DIR/TMP_ALT"
345 resolve_alternates
"$remote" <"$GIT_DIR/TMP_ALT" |
348 case "$alt" in 'bad alternate: '*) die
"$alt";; esac
349 echo >&2 "Getting alternate: $alt"
350 rsync
-av --ignore-existing --exclude info \
351 "$alt" "$GIT_OBJECT_DIRECTORY/" ||
exit
353 rm -f "$GIT_DIR/TMP_ALT"
355 rsync_slurped_objects
=t
359 # We will do git native transport with just one call later.
363 append_fetch_head
"$head" "$remote" \
364 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" ||
exit
369 http
://* | https
://* |
ftp://* | rsync
://* )
370 ;; # we are already done.
372 ( : subshell because we muck with IFS
376 git-fetch-pack
--thin $exec $keep "$remote" $rref ||
echo failed
"$remote"
378 while read sha1 remote_name
382 echo >&2 "Fetch failure: $remote"
384 # special line coming from index-pack with the pack name
388 pack_lockfile
="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
416 local_name
=$
(expr "z$found" : 'z[^:]*:\(.*\)')
417 append_fetch_head
"$sha1" "$remote" \
418 "$remote_name" "$remote_nick" "$local_name" \
419 "$not_for_merge" ||
exit
421 if [ "$pack_lockfile" ]; then rm -f "$pack_lockfile"; fi
427 fetch_main
"$reflist" ||
exit
429 # automated tag following
430 case "$no_tags$tags" in
434 # effective only when we are following remote branch
435 # using local tracking branch.
437 echo "$ls_remote_result" |
438 git-show-ref
--exclude-existing=refs
/tags
/ |
441 git-cat-file
-t "$sha1" >/dev
/null
2>&1 ||
continue
442 echo >&2 "Auto-following $name"
443 echo ".${name}:${name}"
449 fetch_main
"$taglist" ||
exit ;;
453 # If the original head was empty (i.e. no "master" yet), or
454 # if we were told not to worry, we do not have to check.
459 curr_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
460 if test "$curr_head" != "$orig_head"
463 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
465 die
"Cannot fetch into the current branch."