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.
160 fetch_all_at_once
() {
162 eval=$
(echo "$1" | git-fetch--tool parse-reflist
"-")
165 ( : subshell because we muck with IFS
168 if test "$remote" = .
; then
169 git-show-ref
$rref ||
echo failed
"$remote"
170 elif test -f "$remote" ; then
171 test -n "$shallow_depth" &&
172 die
"shallow clone with bundle is not supported"
173 git-bundle unbundle
"$remote" $rref ||
174 echo failed
"$remote"
176 git-fetch-pack
--thin $exec $keep $shallow_depth $no_progress \
178 echo failed
"$remote"
183 test -n "$verbose" && flags
="$flags -v"
184 test -n "$force" && flags
="$flags -f"
185 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION" \
186 git-fetch--tool
$flags native-store \
187 "$remote" "$remote_nick" "$refs"
202 # These are relative path from $GIT_DIR, typically starting at refs/
204 if expr "z$ref" : 'z\.' >/dev
/null
207 ref
=$
(expr "z$ref" : 'z\.\(.*\)')
211 if expr "z$ref" : 'z+' >/dev
/null
214 ref
=$
(expr "z$ref" : 'z+\(.*\)')
218 remote_name
=$
(expr "z$ref" : 'z\([^:]*\):')
219 local_name
=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
221 rref
="$rref$LF$remote_name"
223 # There are transports that can fetch only one head at a time...
225 http
://* | https
://* |
ftp://*)
226 test -n "$shallow_depth" &&
227 die
"shallow clone with http not supported"
228 proto
=`expr "$remote" : '\([^:]*\):'`
229 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
232 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
233 "`git-config --bool http.noEPSV`" = true
]; then
234 noepsv_opt
="--disable-epsv"
237 # Find $remote_name from ls-remote output.
240 echo "$ls_remote_result" |
243 test "z$name" = "z$remote_name" ||
continue
248 expr "z$head" : "z$_x40\$" >/dev
/null ||
249 die
"No such ref $remote_name at $remote"
250 echo >&2 "Fetching $remote_name from $remote using $proto"
251 git-http-fetch
-v -a "$head" "$remote/" ||
exit
254 test -n "$shallow_depth" &&
255 die
"shallow clone with rsync not supported"
256 TMP_HEAD
="$GIT_DIR/TMP_HEAD"
257 rsync
-L -q "$remote/$remote_name" "$TMP_HEAD" ||
exit 1
258 head=$
(git-rev-parse
--verify TMP_HEAD
)
260 test "$rsync_slurped_objects" ||
{
261 rsync
-av --ignore-existing --exclude info \
262 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" ||
exit
264 # Look at objects/info/alternates for rsync -- http will
265 # support it natively and git native ones will do it on
266 # the remote end. Not having that file is not a crime.
267 rsync
-q "$remote/objects/info/alternates" \
268 "$GIT_DIR/TMP_ALT" 2>/dev
/null ||
269 rm -f "$GIT_DIR/TMP_ALT"
270 if test -f "$GIT_DIR/TMP_ALT"
272 resolve_alternates
"$remote" <"$GIT_DIR/TMP_ALT" |
275 case "$alt" in 'bad alternate: '*) die
"$alt";; esac
276 echo >&2 "Getting alternate: $alt"
277 rsync
-av --ignore-existing --exclude info \
278 "$alt" "$GIT_OBJECT_DIRECTORY/" ||
exit
280 rm -f "$GIT_DIR/TMP_ALT"
282 rsync_slurped_objects
=t
287 append_fetch_head
"$head" "$remote" \
288 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" ||
exit
296 http
://* | https
://* |
ftp://* | rsync
://* )
300 fetch_all_at_once
"$@"
305 fetch_main
"$reflist" ||
exit
307 # automated tag following
308 case "$no_tags$tags" in
312 # effective only when we are following remote branch
313 # using local tracking branch.
315 echo "$ls_remote_result" |
316 git-show-ref
--exclude-existing=refs
/tags
/ |
319 git-cat-file
-t "$sha1" >/dev
/null
2>&1 ||
continue
320 echo >&2 "Auto-following $name"
321 echo ".${name}:${name}"
327 # do not deepen a shallow tree when following tags
329 fetch_main
"$taglist" ||
exit ;;
333 # If the original head was empty (i.e. no "master" yet), or
334 # if we were told not to worry, we do not have to check.
339 curr_head
=$
(git-rev-parse
--verify HEAD
2>/dev
/null
)
340 if test "$curr_head" != "$orig_head"
343 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
345 die
"Cannot fetch into the current branch."