git-pull: refuse default merge without branch.*.merge
[gitweb.git] / git-clone.sh
index d4ee93f75bba729c82560f0b2426d8f09f63d82e..422499a5372e5662fbf7ca36ad260229ec03331e 100755 (executable)
@@ -14,7 +14,7 @@ die() {
 }
 
 usage() {
-       die "Usage: $0 [--template=<template_directory>] [--use-immingled-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
+       die "Usage: $0 [--template=<template_directory>] [--no-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
 }
 
 get_repo_base() {
@@ -140,7 +140,7 @@ while
        *,--use-separate-remote)
                # default
                use_separate_remote=t ;;
-       *,--use-immingled-remote)
+       *,--no-separate-remote)
                use_separate_remote= ;;
        1,--reference) usage ;;
        *,--reference)
@@ -176,7 +176,7 @@ repo="$1"
 test -n "$repo" ||
     die 'you must specify a repository to clone.'
 
-# --bare implies --no-checkout and --use-immingled-remote
+# --bare implies --no-checkout and --no-separate-remote
 if test yes = "$bare"
 then
        if test yes = "$origin_override"
@@ -366,41 +366,56 @@ then
                )
        )
 
-       # Write out remotes/$origin file, and update our "$head_points_at".
+       # Write out remote.$origin config, and update our "$head_points_at".
        case "$head_points_at" in
        ?*)
-               mkdir -p "$GIT_DIR/remotes" &&
+               # Local default branch
                git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
+
+               # Tracking branch for the primary branch at the remote.
                case "$use_separate_remote" in
                t)      origin_track="$remote_top/$head_points_at"
                        git-update-ref HEAD "$head_sha1" ;;
                *)      origin_track="$remote_top/$origin"
                        git-update-ref "refs/heads/$origin" "$head_sha1" ;;
                esac &&
-               echo >"$GIT_DIR/remotes/$origin" \
-               "URL: $repo
-Pull: refs/heads/$head_points_at:$origin_track" &&
-               (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
-               while read dotslref
-               do
-                       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" &&
+
+               # Upstream URL and the primary branch tracking
+               git-repo-config remote."$origin".url "$repo" &&
+               git-repo-config remote."$origin".fetch \
+                       "refs/heads/$head_points_at:$origin_track" &&
+
+               # Set up the mappings to track the remaining branches.
+               case "$use_separate_remote" in
+               t)
+                       git-repo-config remote."$origin".fetch \
+                               "refs/heads/*:$remote_top/*" '^$'
+                       ;;
+               *)
+                       (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
+                       while read dotslref
+                       do
+                               name=`expr "$dotslref" : './\(.*\)'`
+                               if test "z$head_points_at" = "z$name" ||
+                                       test "z$origin" = "z$name"
+                               then
+                                       continue
+                               fi
+                               git-repo-config remote."$origin".fetch \
+                               "refs/heads/${name}:$remote_top/${name}" '^$'
+                       done
+                       ;;
+               esac &&
+
                case "$use_separate_remote" in
                t)
                        rm -f "refs/remotes/$origin/HEAD"
                        git-symbolic-ref "refs/remotes/$origin/HEAD" \
                                "refs/remotes/$origin/$head_points_at"
-               esac
+               esac &&
+
+               git-repo-config branch."$head_points_at".remote "$origin" &&
+               git-repo-config branch."$head_points_at".merge "refs/heads/$head_points_at"
        esac
 
        case "$no_checkout" in