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
30 while case "$#" in 0) break ;; esac
33 -a|
--a|
--ap|
--app|
--appe|
--appen|
--append)
36 --upl|
--uplo|
--uploa|
--upload|
--upload-|
--upload-p|\
37 --upload-pa|
--upload-pac|
--upload-pack)
39 exec="--upload-pack=$1"
41 --upl=*|
--uplo=*|
--uploa=*|
--upload=*|\
42 --upload-=*|
--upload-p=*|
--upload-pa=*|
--upload-pac=*|
--upload-pack=*)
43 exec=--upload-pack=$
(expr "z$1" : 'z-[^=]*=\(.*\)')
46 -f|
--f|
--fo|
--for|
--forc|
--force)
49 -t|
--t|
--ta|
--tag|
--tags)
52 -n|
--n|
--no|
--no-|
--no-t|
--no-ta|
--no-tag|
--no-tags)
55 -u|
--u|
--up|
--upd|
--upda|
--updat|
--update|
--update-|
--update-h|\
56 --update-he|
--update-hea|
--update-head|
--update-head-|\
57 --update-head-o|
--update-head-ok)
60 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
66 -k|
--k|
--ke|
--kee|
--keep)
70 shallow_depth
="--depth=`expr "z
$1" : 'z-[^=]*=\(.*\)'`"
74 shallow_depth
="--depth=$1"
88 origin
=$
(get_default_remote
)
89 test -n "$(get_remote_url ${origin})" ||
90 die
"Where do you want to fetch from today?"
91 set x
$origin ; shift ;;
96 # No command line override and we have configuration for the remote.
97 exec="--upload-pack=$(get_uploadpack $1)"
101 remote
=$
(get_remote_url
"$@")
104 rsync_slurped_objects
=
106 if test "" = "$append"
108 : >"$GIT_DIR/FETCH_HEAD"
111 # Global that is reused later
112 ls_remote_result
=$
(git ls-remote
$exec "$remote") ||
113 die
"Cannot get the repository state from $remote"
115 append_fetch_head
() {
117 test -n "$verbose" && flags
="$flags$LF-v"
118 test -n "$force$single_force" && flags
="$flags$LF-f"
119 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION" \
120 git-fetch--tool
$flags append-fetch-head
"$@"
123 # updating the current HEAD with git-fetch in a bare
124 # repository is always fine.
125 if test -z "$update_head_ok" && test $
(is_bare_repository
) = false
127 orig_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
130 # Allow --notags from remote.$1.tagopt
131 case "$tags$no_tags" in
133 case "$(git-config --get "remote.
$1.tagopt
")" in
139 # If --tags (and later --heads or --all) is specified, then we are
140 # not talking about defaults stored in Pull: line of remotes or
141 # branches file, and just fetch those and refspecs explicitly given.
142 # Otherwise we do what we always did.
144 reflist
=$
(get_remote_refs_for_fetch
"$@")
148 echo "$ls_remote_result" |
149 git-show-ref --exclude-existing=refs/tags/ |
152 echo ".${name}:${name}"
156 # remote URL plus explicit refspecs; we need to merge them.
157 reflist
="$reflist$LF$taglist"
159 # No explicit refspecs; fetch tags only.
164 fetch_all_at_once
() {
166 eval=$
(echo "$1" | git-fetch--tool parse-reflist
"-")
169 ( : subshell because we muck with IFS
172 if test "$remote" = .
; then
173 git-show-ref
$rref ||
echo failed
"$remote"
174 elif test -f "$remote" ; then
175 test -n "$shallow_depth" &&
176 die
"shallow clone with bundle is not supported"
177 git-bundle unbundle
"$remote" $rref ||
178 echo failed
"$remote"
180 git-fetch-pack
--thin $exec $keep $shallow_depth \
181 $quiet $no_progress "$remote" $rref ||
182 echo failed
"$remote"
187 test -n "$verbose" && flags
="$flags -v"
188 test -n "$force" && flags
="$flags -f"
189 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION" \
190 git-fetch--tool
$flags native-store \
191 "$remote" "$remote_nick" "$refs"
206 # These are relative path from $GIT_DIR, typically starting at refs/
208 if expr "z$ref" : 'z\.' >/dev
/null
211 ref
=$
(expr "z$ref" : 'z\.\(.*\)')
215 if expr "z$ref" : 'z+' >/dev
/null
218 ref
=$
(expr "z$ref" : 'z+\(.*\)')
222 remote_name
=$
(expr "z$ref" : 'z\([^:]*\):')
223 local_name
=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
225 rref
="$rref$LF$remote_name"
227 # There are transports that can fetch only one head at a time...
229 http
://* | https
://* |
ftp://*)
230 test -n "$shallow_depth" &&
231 die
"shallow clone with http not supported"
232 proto
=`expr "$remote" : '\([^:]*\):'`
233 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
236 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
237 "`git-config --bool http.noEPSV`" = true
]; then
238 noepsv_opt
="--disable-epsv"
241 # Find $remote_name from ls-remote output.
244 echo "$ls_remote_result" |
247 test "z$name" = "z$remote_name" ||
continue
252 expr "z$head" : "z$_x40\$" >/dev
/null ||
253 die
"No such ref $remote_name at $remote"
254 echo >&2 "Fetching $remote_name from $remote using $proto"
255 case "$quiet" in '') v
=-v ;; *) v
= ;; esac
256 git-http-fetch
$v -a "$head" "$remote" ||
exit
259 test -n "$shallow_depth" &&
260 die
"shallow clone with rsync not supported"
261 TMP_HEAD
="$GIT_DIR/TMP_HEAD"
262 rsync
-L -q "$remote/$remote_name" "$TMP_HEAD" ||
exit 1
263 head=$
(git-rev-parse
--verify TMP_HEAD
)
265 case "$quiet" in '') v
=-v ;; *) v
= ;; esac
266 test "$rsync_slurped_objects" ||
{
267 rsync
-a $v --ignore-existing --exclude info \
268 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" ||
exit
270 # Look at objects/info/alternates for rsync -- http will
271 # support it natively and git native ones will do it on
272 # the remote end. Not having that file is not a crime.
273 rsync
-q "$remote/objects/info/alternates" \
274 "$GIT_DIR/TMP_ALT" 2>/dev
/null ||
275 rm -f "$GIT_DIR/TMP_ALT"
276 if test -f "$GIT_DIR/TMP_ALT"
278 resolve_alternates
"$remote" <"$GIT_DIR/TMP_ALT" |
281 case "$alt" in 'bad alternate: '*) die
"$alt";; esac
282 echo >&2 "Getting alternate: $alt"
283 rsync
-av --ignore-existing --exclude info \
284 "$alt" "$GIT_OBJECT_DIRECTORY/" ||
exit
286 rm -f "$GIT_DIR/TMP_ALT"
288 rsync_slurped_objects
=t
293 append_fetch_head
"$head" "$remote" \
294 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" ||
exit
302 http
://* | https
://* |
ftp://* | rsync
://* )
306 fetch_all_at_once
"$@"
311 fetch_main
"$reflist" ||
exit
313 # automated tag following
314 case "$no_tags$tags" in
318 # effective only when we are following remote branch
319 # using local tracking branch.
321 echo "$ls_remote_result" |
322 git-show-ref
--exclude-existing=refs
/tags
/ |
325 git-cat-file
-t "$sha1" >/dev
/null
2>&1 ||
continue
326 echo >&2 "Auto-following $name"
327 echo ".${name}:${name}"
333 # do not deepen a shallow tree when following tags
335 fetch_main
"$taglist" ||
exit ;;
339 # If the original head was empty (i.e. no "master" yet), or
340 # if we were told not to worry, we do not have to check.
345 curr_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
346 if test "$curr_head" != "$orig_head"
349 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
351 die
"Cannot fetch into the current branch."