You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
378 lines
8.9 KiB
378 lines
8.9 KiB
20 years ago
|
#!/bin/sh
|
||
|
#
|
||
19 years ago
|
|
||
|
USAGE='<fetch-options> <repository> <refspec>...'
|
||
18 years ago
|
SUBDIRECTORY_OK=Yes
|
||
19 years ago
|
. git-sh-setup
|
||
18 years ago
|
set_reflog_action "fetch $*"
|
||
18 years ago
|
cd_to_toplevel ;# probably unnecessary...
|
||
18 years ago
|
|
||
20 years ago
|
. git-parse-remote
|
||
20 years ago
|
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
||
|
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
|
||
|
|
||
19 years ago
|
LF='
|
||
|
'
|
||
|
IFS="$LF"
|
||
|
|
||
19 years ago
|
no_tags=
|
||
20 years ago
|
tags=
|
||
20 years ago
|
append=
|
||
20 years ago
|
force=
|
||
19 years ago
|
verbose=
|
||
20 years ago
|
update_head_ok=
|
||
19 years ago
|
exec=
|
||
18 years ago
|
keep=
|
||
18 years ago
|
shallow_depth=
|
||
18 years ago
|
no_progress=
|
||
|
test -t 1 || no_progress=--no-progress
|
||
18 years ago
|
quiet=
|
||
18 years ago
|
while test $# != 0
|
||
20 years ago
|
do
|
||
|
case "$1" in
|
||
|
-a|--a|--ap|--app|--appe|--appen|--append)
|
||
|
append=t
|
||
|
;;
|
||
19 years ago
|
--upl|--uplo|--uploa|--upload|--upload-|--upload-p|\
|
||
|
--upload-pa|--upload-pac|--upload-pack)
|
||
19 years ago
|
shift
|
||
18 years ago
|
exec="--upload-pack=$1"
|
||
|
;;
|
||
|
--upl=*|--uplo=*|--uploa=*|--upload=*|\
|
||
|
--upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
|
||
18 years ago
|
exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
|
||
18 years ago
|
shift
|
||
19 years ago
|
;;
|
||
20 years ago
|
-f|--f|--fo|--for|--forc|--force)
|
||
|
force=t
|
||
20 years ago
|
;;
|
||
20 years ago
|
-t|--t|--ta|--tag|--tags)
|
||
|
tags=t
|
||
|
;;
|
||
19 years ago
|
-n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags)
|
||
|
no_tags=t
|
||
|
;;
|
||
20 years ago
|
-u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
|
||
|
--update-he|--update-hea|--update-head|--update-head-|\
|
||
|
--update-head-o|--update-head-ok)
|
||
|
update_head_ok=t
|
||
20 years ago
|
;;
|
||
18 years ago
|
-q|--q|--qu|--qui|--quie|--quiet)
|
||
|
quiet=--quiet
|
||
|
;;
|
||
19 years ago
|
-v|--verbose)
|
||
18 years ago
|
verbose="$verbose"Yes
|
||
19 years ago
|
;;
|
||
19 years ago
|
-k|--k|--ke|--kee|--keep)
|
||
18 years ago
|
keep='-k -k'
|
||
19 years ago
|
;;
|
||
18 years ago
|
--depth=*)
|
||
|
shallow_depth="--depth=`expr "z$1" : 'z-[^=]*=\(.*\)'`"
|
||
|
;;
|
||
|
--depth)
|
||
|
shift
|
||
|
shallow_depth="--depth=$1"
|
||
|
;;
|
||
19 years ago
|
-*)
|
||
|
usage
|
||
|
;;
|
||
20 years ago
|
*)
|
||
|
break
|
||
|
;;
|
||
|
esac
|
||
20 years ago
|
shift
|
||
20 years ago
|
done
|
||
|
|
||
20 years ago
|
case "$#" in
|
||
|
0)
|
||
19 years ago
|
origin=$(get_default_remote)
|
||
|
test -n "$(get_remote_url ${origin})" ||
|
||
|
die "Where do you want to fetch from today?"
|
||
|
set x $origin ; shift ;;
|
||
20 years ago
|
esac
|
||
20 years ago
|
|
||
18 years ago
|
if test -z "$exec"
|
||
|
then
|
||
|
# No command line override and we have configuration for the remote.
|
||
|
exec="--upload-pack=$(get_uploadpack $1)"
|
||
|
fi
|
||
|
|
||
20 years ago
|
remote_nick="$1"
|
||
|
remote=$(get_remote_url "$@")
|
||
|
refs=
|
||
|
rref=
|
||
|
rsync_slurped_objects=
|
||
|
|
||
|
if test "" = "$append"
|
||
|
then
|
||
20 years ago
|
: >"$GIT_DIR/FETCH_HEAD"
|
||
20 years ago
|
fi
|
||
|
|
||
18 years ago
|
# Global that is reused later
|
||
18 years ago
|
ls_remote_result=$(git ls-remote $exec "$remote") ||
|
||
18 years ago
|
die "Cannot get the repository state from $remote"
|
||
18 years ago
|
|
||
20 years ago
|
append_fetch_head () {
|
||
18 years ago
|
flags=
|
||
18 years ago
|
test -n "$verbose" && flags="$flags$LF-v"
|
||
|
test -n "$force$single_force" && flags="$flags$LF-f"
|
||
18 years ago
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
|
||
18 years ago
|
git fetch--tool $flags append-fetch-head "$@"
|
||
20 years ago
|
}
|
||
|
|
||
18 years ago
|
# updating the current HEAD with git-fetch in a bare
|
||
|
# repository is always fine.
|
||
|
if test -z "$update_head_ok" && test $(is_bare_repository) = false
|
||
|
then
|
||
18 years ago
|
orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
|
||
18 years ago
|
fi
|
||
20 years ago
|
|
||
18 years ago
|
# Allow --notags from remote.$1.tagopt
|
||
|
case "$tags$no_tags" in
|
||
|
'')
|
||
18 years ago
|
case "$(git config --get "remote.$1.tagopt")" in
|
||
18 years ago
|
--no-tags)
|
||
|
no_tags=t ;;
|
||
|
esac
|
||
|
esac
|
||
|
|
||
20 years ago
|
# If --tags (and later --heads or --all) is specified, then we are
|
||
|
# not talking about defaults stored in Pull: line of remotes or
|
||
|
# branches file, and just fetch those and refspecs explicitly given.
|
||
|
# Otherwise we do what we always did.
|
||
|
|
||
|
reflist=$(get_remote_refs_for_fetch "$@")
|
||
|
if test "$tags"
|
||
|
then
|
||
18 years ago
|
taglist=`IFS=' ' &&
|
||
18 years ago
|
echo "$ls_remote_result" |
|
||
18 years ago
|
git show-ref --exclude-existing=refs/tags/ |
|
||
19 years ago
|
while read sha1 name
|
||
|
do
|
||
18 years ago
|
echo ".${name}:${name}"
|
||
19 years ago
|
done` || exit
|
||
20 years ago
|
if test "$#" -gt 1
|
||
|
then
|
||
|
# remote URL plus explicit refspecs; we need to merge them.
|
||
19 years ago
|
reflist="$reflist$LF$taglist"
|
||
20 years ago
|
else
|
||
|
# No explicit refspecs; fetch tags only.
|
||
|
reflist=$taglist
|
||
|
fi
|
||
|
fi
|
||
|
|
||
18 years ago
|
fetch_all_at_once () {
|
||
18 years ago
|
|
||
18 years ago
|
eval=$(echo "$1" | git fetch--tool parse-reflist "-")
|
||
18 years ago
|
eval "$eval"
|
||
18 years ago
|
|
||
|
( : subshell because we muck with IFS
|
||
|
IFS=" $LF"
|
||
|
(
|
||
18 years ago
|
if test "$remote" = . ; then
|
||
18 years ago
|
git show-ref $rref || echo failed "$remote"
|
||
18 years ago
|
elif test -f "$remote" ; then
|
||
18 years ago
|
test -n "$shallow_depth" &&
|
||
|
die "shallow clone with bundle is not supported"
|
||
18 years ago
|
git bundle unbundle "$remote" $rref ||
|
||
18 years ago
|
echo failed "$remote"
|
||
|
else
|
||
18 years ago
|
if test -d "$remote" &&
|
||
|
|
||
|
# The remote might be our alternate. With
|
||
|
# this optimization we will bypass fetch-pack
|
||
|
# altogether, which means we cannot be doing
|
||
|
# the shallow stuff at all.
|
||
|
test ! -f "$GIT_DIR/shallow" &&
|
||
|
test -z "$shallow_depth" &&
|
||
|
|
||
|
# See if all of what we are going to fetch are
|
||
|
# connected to our repository's tips, in which
|
||
|
# case we do not have to do any fetch.
|
||
18 years ago
|
theirs=$(echo "$ls_remote_result" | \
|
||
18 years ago
|
git fetch--tool -s pick-rref "$rref" "-") &&
|
||
18 years ago
|
|
||
|
# This will barf when $theirs reach an object that
|
||
|
# we do not have in our repository. Otherwise,
|
||
|
# we already have everything the fetch would bring in.
|
||
18 years ago
|
git rev-list --objects $theirs --not --all \
|
||
18 years ago
|
>/dev/null 2>/dev/null
|
||
|
then
|
||
18 years ago
|
echo "$ls_remote_result" | \
|
||
18 years ago
|
git fetch--tool pick-rref "$rref" "-"
|
||
18 years ago
|
else
|
||
18 years ago
|
flags=
|
||
|
case $verbose in
|
||
|
YesYes*)
|
||
|
flags="-v"
|
||
|
;;
|
||
|
esac
|
||
18 years ago
|
git-fetch-pack --thin $exec $keep $shallow_depth \
|
||
18 years ago
|
$quiet $no_progress $flags "$remote" $rref ||
|
||
18 years ago
|
echo failed "$remote"
|
||
|
fi
|
||
18 years ago
|
fi
|
||
18 years ago
|
) |
|
||
|
(
|
||
18 years ago
|
flags=
|
||
|
test -n "$verbose" && flags="$flags -v"
|
||
|
test -n "$force" && flags="$flags -f"
|
||
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
|
||
18 years ago
|
git fetch--tool $flags native-store \
|
||
18 years ago
|
"$remote" "$remote_nick" "$refs"
|
||
18 years ago
|
)
|
||
|
) || exit
|
||
|
|
||
|
}
|
||
|
|
||
18 years ago
|
fetch_per_ref () {
|
||
19 years ago
|
reflist="$1"
|
||
|
refs=
|
||
19 years ago
|
rref=
|
||
20 years ago
|
|
||
19 years ago
|
for ref in $reflist
|
||
|
do
|
||
|
refs="$refs$LF$ref"
|
||
20 years ago
|
|
||
19 years ago
|
# These are relative path from $GIT_DIR, typically starting at refs/
|
||
|
# but may be HEAD
|
||
19 years ago
|
if expr "z$ref" : 'z\.' >/dev/null
|
||
19 years ago
|
then
|
||
|
not_for_merge=t
|
||
19 years ago
|
ref=$(expr "z$ref" : 'z\.\(.*\)')
|
||
19 years ago
|
else
|
||
|
not_for_merge=
|
||
|
fi
|
||
19 years ago
|
if expr "z$ref" : 'z+' >/dev/null
|
||
19 years ago
|
then
|
||
|
single_force=t
|
||
19 years ago
|
ref=$(expr "z$ref" : 'z+\(.*\)')
|
||
19 years ago
|
else
|
||
|
single_force=
|
||
|
fi
|
||
19 years ago
|
remote_name=$(expr "z$ref" : 'z\([^:]*\):')
|
||
|
local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
|
||
20 years ago
|
|
||
19 years ago
|
rref="$rref$LF$remote_name"
|
||
20 years ago
|
|
||
19 years ago
|
# There are transports that can fetch only one head at a time...
|
||
|
case "$remote" in
|
||
19 years ago
|
http://* | https://* | ftp://*)
|
||
18 years ago
|
test -n "$shallow_depth" &&
|
||
|
die "shallow clone with http not supported"
|
||
18 years ago
|
proto=`expr "$remote" : '\([^:]*\):'`
|
||
19 years ago
|
if [ -n "$GIT_SSL_NO_VERIFY" ]; then
|
||
|
curl_extra_args="-k"
|
||
|
fi
|
||
19 years ago
|
if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
|
||
18 years ago
|
"`git config --bool http.noEPSV`" = true ]; then
|
||
19 years ago
|
noepsv_opt="--disable-epsv"
|
||
|
fi
|
||
18 years ago
|
|
||
|
# Find $remote_name from ls-remote output.
|
||
18 years ago
|
head=$(echo "$ls_remote_result" | \
|
||
18 years ago
|
git fetch--tool -s pick-rref "$remote_name" "-")
|
||
19 years ago
|
expr "z$head" : "z$_x40\$" >/dev/null ||
|
||
18 years ago
|
die "No such ref $remote_name at $remote"
|
||
18 years ago
|
echo >&2 "Fetching $remote_name from $remote using $proto"
|
||
18 years ago
|
case "$quiet" in '') v=-v ;; *) v= ;; esac
|
||
18 years ago
|
git-http-fetch $v -a "$head" "$remote" || exit
|
||
19 years ago
|
;;
|
||
|
rsync://*)
|
||
18 years ago
|
test -n "$shallow_depth" &&
|
||
|
die "shallow clone with rsync not supported"
|
||
19 years ago
|
TMP_HEAD="$GIT_DIR/TMP_HEAD"
|
||
|
rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
|
||
18 years ago
|
head=$(git rev-parse --verify TMP_HEAD)
|
||
19 years ago
|
rm -f "$TMP_HEAD"
|
||
18 years ago
|
case "$quiet" in '') v=-v ;; *) v= ;; esac
|
||
19 years ago
|
test "$rsync_slurped_objects" || {
|
||
18 years ago
|
rsync -a $v --ignore-existing --exclude info \
|
||
19 years ago
|
"$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
|
||
20 years ago
|
|
||
19 years ago
|
# Look at objects/info/alternates for rsync -- http will
|
||
|
# support it natively and git native ones will do it on
|
||
|
# the remote end. Not having that file is not a crime.
|
||
|
rsync -q "$remote/objects/info/alternates" \
|
||
|
"$GIT_DIR/TMP_ALT" 2>/dev/null ||
|
||
|
rm -f "$GIT_DIR/TMP_ALT"
|
||
|
if test -f "$GIT_DIR/TMP_ALT"
|
||
|
then
|
||
|
resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
|
||
|
while read alt
|
||
|
do
|
||
|
case "$alt" in 'bad alternate: '*) die "$alt";; esac
|
||
|
echo >&2 "Getting alternate: $alt"
|
||
|
rsync -av --ignore-existing --exclude info \
|
||
|
"$alt" "$GIT_OBJECT_DIRECTORY/" || exit
|
||
|
done
|
||
|
rm -f "$GIT_DIR/TMP_ALT"
|
||
|
fi
|
||
|
rsync_slurped_objects=t
|
||
|
}
|
||
|
;;
|
||
|
esac
|
||
20 years ago
|
|
||
19 years ago
|
append_fetch_head "$head" "$remote" \
|
||
18 years ago
|
"$remote_name" "$remote_nick" "$local_name" "$not_for_merge" || exit
|
||
20 years ago
|
|
||
19 years ago
|
done
|
||
|
|
||
18 years ago
|
}
|
||
19 years ago
|
|
||
18 years ago
|
fetch_main () {
|
||
|
case "$remote" in
|
||
|
http://* | https://* | ftp://* | rsync://* )
|
||
18 years ago
|
fetch_per_ref "$@"
|
||
18 years ago
|
;;
|
||
|
*)
|
||
18 years ago
|
fetch_all_at_once "$@"
|
||
18 years ago
|
;;
|
||
|
esac
|
||
19 years ago
|
}
|
||
|
|
||
18 years ago
|
fetch_main "$reflist" || exit
|
||
19 years ago
|
|
||
|
# automated tag following
|
||
|
case "$no_tags$tags" in
|
||
|
'')
|
||
19 years ago
|
case "$reflist" in
|
||
|
*:refs/*)
|
||
|
# effective only when we are following remote branch
|
||
|
# using local tracking branch.
|
||
18 years ago
|
taglist=$(IFS=' ' &&
|
||
18 years ago
|
echo "$ls_remote_result" |
|
||
18 years ago
|
git show-ref --exclude-existing=refs/tags/ |
|
||
19 years ago
|
while read sha1 name
|
||
|
do
|
||
18 years ago
|
git cat-file -t "$sha1" >/dev/null 2>&1 || continue
|
||
19 years ago
|
echo >&2 "Auto-following $name"
|
||
|
echo ".${name}:${name}"
|
||
|
done)
|
||
|
esac
|
||
19 years ago
|
case "$taglist" in
|
||
|
'') ;;
|
||
|
?*)
|
||
18 years ago
|
# do not deepen a shallow tree when following tags
|
||
|
shallow_depth=
|
||
18 years ago
|
fetch_main "$taglist" || exit ;;
|
||
19 years ago
|
esac
|
||
20 years ago
|
esac
|
||
20 years ago
|
|
||
|
# If the original head was empty (i.e. no "master" yet), or
|
||
|
# if we were told not to worry, we do not have to check.
|
||
18 years ago
|
case "$orig_head" in
|
||
|
'')
|
||
20 years ago
|
;;
|
||
18 years ago
|
?*)
|
||
18 years ago
|
curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
|
||
20 years ago
|
if test "$curr_head" != "$orig_head"
|
||
|
then
|
||
18 years ago
|
git update-ref \
|
||
18 years ago
|
-m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
|
||
19 years ago
|
HEAD "$orig_head"
|
||
20 years ago
|
die "Cannot fetch into the current branch."
|
||
|
fi
|
||
|
;;
|
||
|
esac
|