Code

git-fetch.sh printed protocol fix
[git.git] / git-clone.sh
index c013e481d044b3b11155d970f785766bc4c18613..24b119537bf5ed926235aabfceb8e4526af6f77a 100755 (executable)
@@ -9,7 +9,7 @@
 unset CDPATH
 
 usage() {
-       echo >&2 "Usage: $0 [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
+       echo >&2 "Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
        exit 1
 }
 
@@ -29,8 +29,12 @@ http_fetch () {
 clone_dumb_http () {
        # $1 - remote, $2 - local
        cd "$2" &&
-       clone_tmp='.git/clone-tmp' &&
+       clone_tmp="$GIT_DIR/clone-tmp" &&
        mkdir -p "$clone_tmp" || exit 1
+       if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
+               "`git-repo-config --bool http.noEPSV`" = true ]; then
+               curl_extra_args="${curl_extra_args} --disable-epsv"
+       fi
        http_fetch "$1/info/refs" "$clone_tmp/refs" || {
                echo >&2 "Cannot get remote repository information.
 Perhaps git-update-server-info needs to be run there?"
@@ -38,12 +42,12 @@ Perhaps git-update-server-info needs to be run there?"
        }
        while read sha1 refname
        do
-               name=`expr "$refname" : 'refs/\(.*\)'` &&
+               name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
                case "$name" in
                *^*)    continue;;
                esac
                if test -n "$use_separate_remote" &&
-                  branch_name=`expr "$name" : 'heads/\(.*\)'`
+                  branch_name=`expr "z$name" : 'zheads/\(.*\)'`
                then
                        tname="remotes/$origin/$branch_name"
                else
@@ -102,6 +106,7 @@ quiet=
 local=no
 use_local=no
 local_shared=no
+unset template
 no_checkout=
 upload_pack=
 bare=
@@ -120,6 +125,11 @@ while
        *,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes ;;
         *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared) 
           local_shared=yes; use_local=yes ;;
+       1,--template) usage ;;
+       *,--template)
+               shift; template="--template=$1" ;;
+       *,--template=*)
+         template="$1" ;;
        *,-q|*,--quiet) quiet=-q ;;
        *,--use-separate-remote)
                use_separate_remote=t ;;
@@ -127,7 +137,7 @@ while
        *,--reference)
                shift; reference="$1" ;;
        *,--reference=*)
-               reference=`expr "$1" : '--reference=\(.*\)'` ;;
+               reference=`expr "z$1" : 'z--reference=\(.*\)'` ;;
        *,-o|*,--or|*,--ori|*,--orig|*,--origi|*,--origin)
                case "$2" in
                '')
@@ -199,17 +209,13 @@ dir="$2"
 [ -e "$dir" ] && echo "$dir already exists." && usage
 mkdir -p "$dir" &&
 D=$(cd "$dir" && pwd) &&
-trap 'err=$?; cd ..; rm -r "$D"; exit $err' exit
-case "$bare" in
-yes) GIT_DIR="$D" ;;
-*) GIT_DIR="$D/.git" ;;
-esac && export GIT_DIR && git-init-db || usage
+trap 'err=$?; cd ..; rm -rf "$D"; exit $err' 0
 case "$bare" in
 yes)
        GIT_DIR="$D" ;;
 *)
        GIT_DIR="$D/.git" ;;
-esac
+esac && export GIT_DIR && git-init-db ${template+"$template"} || usage
 
 if test -n "$reference"
 then
@@ -261,14 +267,10 @@ yes,yes)
            ;;
        yes)
            mkdir -p "$GIT_DIR/objects/info"
-           {
-               test -f "$repo/objects/info/alternates" &&
-               cat "$repo/objects/info/alternates";
-               echo "$repo/objects"
-           } >"$GIT_DIR/objects/info/alternates"
+           echo "$repo/objects" >> "$GIT_DIR/objects/info/alternates"
            ;;
        esac
-       git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD"
+       git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
        ;;
 *)
        case "$repo" in
@@ -298,9 +300,9 @@ yes,yes)
                    done
                    rm -f "$GIT_DIR/TMP_ALT"
                fi
-               git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD"
+               git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
                ;;
-       http://*)
+       https://*|http://*|ftp://*)
                if test -z "@@NO_CURL@@"
                then
                        clone_dumb_http "$repo" "$D"
@@ -310,7 +312,7 @@ yes,yes)
                fi
                ;;
        *)
-               cd "$D" && case "$upload_pack" in
+               case "$upload_pack" in
                '') git-fetch-pack --all -k $quiet "$repo" ;;
                *) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
                esac >"$GIT_DIR/CLONE_HEAD" || {
@@ -326,7 +328,8 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
 if test -f "$GIT_DIR/CLONE_HEAD"
 then
        # Read git-fetch-pack -k output and store the remote branches.
-       perl -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin"
+       @@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
+       exit
 fi
 
 cd "$D" || exit
@@ -346,7 +349,7 @@ then
                # new style repository with a symref HEAD).
                # Ideally we should skip the guesswork but for now
                # opt for minimum change.
-               head_sha1=`expr "$head_sha1" : 'ref: refs/heads/\(.*\)'`
+               head_sha1=`expr "z$head_sha1" : 'zref: refs/heads/\(.*\)'`
                head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"`
                ;;
        esac
@@ -389,11 +392,16 @@ Pull: refs/heads/$head_points_at:$origin_track" &&
                (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
                while read dotslref
                do
-                       name=`expr "$dotslref" : './\(.*\)'` &&
-                       test "$use_separate_remote" = '' && {
-                               test "$head_points_at" = "$name" ||
-                               test "$origin" = "$name"
-                       } ||
+                       name=`expr "$dotslref" : './\(.*\)'`
+                       if test "z$head_points_at" = "z$name"
+                       then
+                               continue
+                       fi
+                       if test "$use_separate_remote" = '' &&
+                          test "z$origin" = "z$name"
+                       then
+                               continue
+                       fi
                        echo "Pull: refs/heads/${name}:$remote_top/${name}"
                done >>"$GIT_DIR/remotes/$origin" &&
                case "$use_separate_remote" in
@@ -406,10 +414,11 @@ Pull: refs/heads/$head_points_at:$origin_track" &&
 
        case "$no_checkout" in
        '')
-               git-read-tree -m -u -v HEAD HEAD
+               test "z$quiet" = z && v=-v || v=
+               git-read-tree -m -u $v HEAD HEAD
        esac
 fi
 rm -f "$GIT_DIR/CLONE_HEAD" "$GIT_DIR/REMOTE_HEAD"
 
-trap - exit
+trap - 0