Code

change quoting in test t1006-cat-file.sh
[git.git] / git-clone.sh
index b4e858c3885dab55398670d9497304eb83545d1f..8c7fc7f6317113fcef923dcc625fb94e13fb77a0 100755 (executable)
@@ -210,11 +210,29 @@ if base=$(get_repo_base "$repo"); then
        then
                local=yes
        fi
+elif test -f "$repo"
+then
+       case "$repo" in /*) ;; *) repo="$PWD/$repo" ;; esac
+fi
+
+# Decide the directory name of the new repository
+if test -n "$2"
+then
+       dir="$2"
+       test $# = 2 || die "excess parameter to git-clone"
+else
+       # Derive one from the repository name
+       # Try using "humanish" part of source repo if user didn't specify one
+       if test -f "$repo"
+       then
+               # Cloning from a bundle
+               dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
+       else
+               dir=$(echo "$repo" |
+                       sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+       fi
 fi
 
-dir="$2"
-# Try using "humanish" part of source repo if user didn't specify one
-[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
 [ -e "$dir" ] && die "destination directory '$dir' already exists."
 [ yes = "$bare" ] && unset GIT_WORK_TREE
 [ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
@@ -293,6 +311,9 @@ yes)
                mkdir -p "$GIT_DIR/objects/info"
                echo "$repo/objects" >>"$GIT_DIR/objects/info/alternates"
        else
+               cpio_quiet_flag=""
+               cpio --help 2>&1 | grep -- --quiet >/dev/null && \
+                       cpio_quiet_flag=--quiet
                l= &&
                if test "$use_local_hardlink" = yes
                then
@@ -313,7 +334,8 @@ yes)
                        fi
                fi &&
                cd "$repo" &&
-               find objects -depth -print | cpio -pumd$l "$GIT_DIR/" || exit 1
+               find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
+                       exit 1
        fi
        git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
        ;;
@@ -364,11 +386,17 @@ yes)
                fi
                ;;
        *)
-               case "$upload_pack" in
-               '') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
-               *) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
-               esac >"$GIT_DIR/CLONE_HEAD" ||
+               if [ -f "$repo" ] ; then
+                       git bundle unbundle "$repo" > "$GIT_DIR/CLONE_HEAD" ||
+                       die "unbundle from '$repo' failed."
+               else
+                       case "$upload_pack" in
+                       '') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
+                       *) git-fetch-pack --all -k \
+                               $quiet "$upload_pack" $depth $no_progress "$repo" ;;
+                       esac >"$GIT_DIR/CLONE_HEAD" ||
                        die "fetch-pack from '$repo' failed."
+               fi
                ;;
        esac
        ;;
@@ -409,11 +437,12 @@ else
        cd "$D" || exit
 fi
 
-if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
+if test -z "$bare"
 then
        # a non-bare repository is always in separate-remote layout
        remote_top="refs/remotes/$origin"
-       head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+       head_sha1=
+       test ! -r "$GIT_DIR/REMOTE_HEAD" || head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
        case "$head_sha1" in
        'ref: refs/'*)
                # Uh-oh, the remote told us (http transport done against
@@ -470,9 +499,16 @@ then
                git config branch."$head_points_at".merge "refs/heads/$head_points_at"
                ;;
        '')
-               # Source had detached HEAD pointing nowhere
-               git update-ref --no-deref HEAD "$head_sha1" &&
-               rm -f "refs/remotes/$origin/HEAD"
+               if test -z "$head_sha1"
+               then
+                       # Source had nonexistent ref in HEAD
+                       echo >&2 "Warning: Remote HEAD refers to nonexistent ref, unable to checkout."
+                       no_checkout=t
+               else
+                       # Source had detached HEAD pointing nowhere
+                       git update-ref --no-deref HEAD "$head_sha1" &&
+                       rm -f "refs/remotes/$origin/HEAD"
+               fi
                ;;
        esac