4 USAGE='<fetch-options> <repository> <refspec>...'
7 set_reflog_action "fetch $*"
8 cd_to_toplevel ;# probably unnecessary...
11 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
28 test -t 1 || no_progress=--no-progress
29 while case "$#" in 0) break ;; esac
32 -a|--a|--ap|--app|--appe|--appen|--append)
35 --upl|--uplo|--uploa|--upload|--upload-|--upload-p|\
36 --upload-pa|--upload-pac|--upload-pack)
38 exec="--upload-pack=$1"
40 --upl=*|--uplo=*|--uploa=*|--upload=*|\
41 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
42 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
45 -f|--f|--fo|--for|--forc|--force)
48 -t|--t|--ta|--tag|--tags)
51 -n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags)
54 -u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
55 --update-he|--update-hea|--update-head|--update-head-|\
56 --update-head-o|--update-head-ok)
62 -k|--k|--ke|--kee|--keep)
66 shallow_depth="--depth=`expr "z$1" : 'z-[^=]*=\(.*\)'`"
70 shallow_depth="--depth=$1"
84 origin=$(get_default_remote)
85 test -n "$(get_remote_url ${origin})" ||
86 die "Where do you want to fetch from today?"
87 set x $origin ; shift ;;
92 # No command line override and we have configuration for the remote.
93 exec="--upload-pack=$(get_uploadpack $1)"
97 remote=$(get_remote_url "$@")
100 rsync_slurped_objects=
102 if test "" = "$append"
104 : >"$GIT_DIR/FETCH_HEAD"
107 # Global that is reused later
108 ls_remote_result=$(git ls-remote $exec "$remote") ||
109 die "Cannot get the repository state from $remote"
111 append_fetch_head () {
113 test -n "$verbose" && flags="$flags -v"
114 test -n "$force" && flags="$flags -f"
115 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
116 git-fetch--tool $flags append-fetch-head "$@"
119 # updating the current HEAD with git-fetch in a bare
120 # repository is always fine.
121 if test -z "$update_head_ok" && test $(is_bare_repository) = false
123 orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
126 # Allow --notags from remote.$1.tagopt
127 case "$tags$no_tags" in
129 case "$(git-config --get "remote.$1.tagopt")" in
135 # If --tags (and later --heads or --all) is specified, then we are
136 # not talking about defaults stored in Pull: line of remotes or
137 # branches file, and just fetch those and refspecs explicitly given.
138 # Otherwise we do what we always did.
140 reflist=$(get_remote_refs_for_fetch "$@")
144 echo "$ls_remote_result" |
145 git-show-ref --exclude-existing=refs/tags/ |
148 echo ".${name}:${name}"
152 # remote URL plus explicit refspecs; we need to merge them.
153 reflist="$reflist$LF$taglist"
155 # No explicit refspecs; fetch tags only.
162 eval=$(echo "$1" | git-fetch--tool parse-reflist "-")
165 ( : subshell because we muck with IFS
168 if test -f "$remote" ; then
169 test -n "$shallow_depth" &&
170 die "shallow clone with bundle is not supported"
171 git-bundle unbundle "$remote" $rref ||
172 echo failed "$remote"
174 git-fetch-pack --thin $exec $keep $shallow_depth $no_progress \
176 echo failed "$remote"
181 test -n "$verbose" && flags="$flags -v"
182 test -n "$force" && flags="$flags -f"
183 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
184 git-fetch--tool $flags native-store \
185 "$remote" "$remote_nick" "$refs"
200 # These are relative path from $GIT_DIR, typically starting at refs/
202 if expr "z$ref" : 'z\.' >/dev/null
205 ref=$(expr "z$ref" : 'z\.\(.*\)')
209 if expr "z$ref" : 'z+' >/dev/null
212 ref=$(expr "z$ref" : 'z+\(.*\)')
216 remote_name=$(expr "z$ref" : 'z\([^:]*\):')
217 local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
219 rref="$rref$LF$remote_name"
221 # There are transports that can fetch only one head at a time...
223 http://* | https://* | ftp://*)
224 test -n "$shallow_depth" &&
225 die "shallow clone with http not supported"
226 proto=`expr "$remote" : '\([^:]*\):'`
227 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
230 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
231 "`git-config --bool http.noEPSV`" = true ]; then
232 noepsv_opt="--disable-epsv"
235 # Find $remote_name from ls-remote output.
238 echo "$ls_remote_result" |
241 test "z$name" = "z$remote_name" || continue
246 expr "z$head" : "z$_x40\$" >/dev/null ||
247 die "No such ref $remote_name at $remote"
248 echo >&2 "Fetching $remote_name from $remote using $proto"
249 git-http-fetch -v -a "$head" "$remote/" || exit
252 test -n "$shallow_depth" &&
253 die "shallow clone with rsync not supported"
254 TMP_HEAD="$GIT_DIR/TMP_HEAD"
255 rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
256 head=$(git-rev-parse --verify TMP_HEAD)
258 test "$rsync_slurped_objects" || {
259 rsync -av --ignore-existing --exclude info \
260 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
262 # Look at objects/info/alternates for rsync -- http will
263 # support it natively and git native ones will do it on
264 # the remote end. Not having that file is not a crime.
265 rsync -q "$remote/objects/info/alternates" \
266 "$GIT_DIR/TMP_ALT" 2>/dev/null ||
267 rm -f "$GIT_DIR/TMP_ALT"
268 if test -f "$GIT_DIR/TMP_ALT"
270 resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
273 case "$alt" in 'bad alternate: '*) die "$alt";; esac
274 echo >&2 "Getting alternate: $alt"
275 rsync -av --ignore-existing --exclude info \
276 "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
278 rm -f "$GIT_DIR/TMP_ALT"
280 rsync_slurped_objects=t
285 append_fetch_head "$head" "$remote" \
286 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" || exit
294 http://* | https://* | ftp://* | rsync://* )
303 fetch_main "$reflist" || exit
305 # automated tag following
306 case "$no_tags$tags" in
310 # effective only when we are following remote branch
311 # using local tracking branch.
313 echo "$ls_remote_result" |
314 git-show-ref --exclude-existing=refs/tags/ |
317 git-cat-file -t "$sha1" >/dev/null 2>&1 || continue
318 echo >&2 "Auto-following $name"
319 echo ".${name}:${name}"
325 # do not deepen a shallow tree when following tags
327 fetch_main "$taglist" || exit ;;
331 # If the original head was empty (i.e. no "master" yet), or
332 # if we were told not to worry, we do not have to check.
337 curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
338 if test "$curr_head" != "$orig_head"
341 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
343 die "Cannot fetch into the current branch."