Merge branch 'js/rebase'
[gitweb.git] / git-clone.sh
index 3a410624d374e9d02b305a25469176e4d4e725e6..4cbf60f554cee4560559cc3aa4e7d6fbb90e68ed 100755 (executable)
@@ -72,6 +72,17 @@ Perhaps git-update-server-info needs to be run there?"
        rm -fr "$clone_tmp"
        http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
        rm -f "$GIT_DIR/REMOTE_HEAD"
+       if test -f "$GIT_DIR/REMOTE_HEAD"; then
+               head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+               case "$head_sha1" in
+               'ref: refs/'*)
+                       ;;
+               *)
+                       git-http-fetch $v -a "$head_sha1" "$1" ||
+                       rm -f "$GIT_DIR/REMOTE_HEAD"
+                       ;;
+               esac
+       fi
 }
 
 quiet=
@@ -377,6 +388,13 @@ then
                )
        )
 
+       # Upstream URL
+       git-config remote."$origin".url "$repo" &&
+
+       # Set up the mappings to track the remote branches.
+       git-config remote."$origin".fetch \
+               "+refs/heads/*:$remote_top/*" '^$' &&
+
        # Write out remote.$origin config, and update our "$head_points_at".
        case "$head_points_at" in
        ?*)
@@ -384,21 +402,20 @@ then
                git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
 
                # Tracking branch for the primary branch at the remote.
-               origin_track="$remote_top/$head_points_at" &&
                git-update-ref HEAD "$head_sha1" &&
 
-               # Upstream URL
-               git-config remote."$origin".url "$repo" &&
-
-               # Set up the mappings to track the remote branches.
-               git-config remote."$origin".fetch \
-                       "+refs/heads/*:$remote_top/*" '^$' &&
                rm -f "refs/remotes/$origin/HEAD"
                git-symbolic-ref "refs/remotes/$origin/HEAD" \
                        "refs/remotes/$origin/$head_points_at" &&
 
                git-config branch."$head_points_at".remote "$origin" &&
                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"
+               ;;
        esac
 
        case "$no_checkout" in