@matheusbsbs / matheus-bagliano / commits / 61dde8f916
Fork 0

git-clone: use wildcard specification for tracking branches

This stops enumerating the set of branches found on the remote side when a clone was made in the configuration file. Instead, a single entry that maps each remote branch to the local tracking branch for the remote under the same name is created. Doing it this way not only shortens the configuration file, but automatically adjusts to a new branch added on the remote side after the clone is made. Unfortunately this cannot be done for the traditional layout, where we always need to special case the 'master' to 'origin' mapping within the local branch namespace. But that is Ok; it will be going away before v1.5.0. We could also lose the "primary branch" mapping at the beginning, but that has to wait until we implement the "forbid 'git pull' when we do not have branch.$current.merge for the current branch" policy we earlier discussed. That should also be in v1.5.0 Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 16, 2006 at 01:14 UTC 61dde8f91672ab362f3cfd3af8d6d09d448d4ffe
1 file changed +30 -17
git-clone.sh
+30 -17
@@ -366,41 +366,54 @@ then
366 )
367 )
368
369 - # Write out remotes/$origin file, and update our "$head_points_at".
369 + # Write out remote.$origin config, and update our "$head_points_at".
370 case "$head_points_at" in
371 ?*)
372 - mkdir -p "$GIT_DIR/remotes" &&
372 + # Local default branch
373 git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
374 +
375 + # Tracking branch for the primary branch at the remote.
376 case "$use_separate_remote" in
377 t) origin_track="$remote_top/$head_points_at"
378 git-update-ref HEAD "$head_sha1" ;;
379 *) origin_track="$remote_top/$origin"
380 git-update-ref "refs/heads/$origin" "$head_sha1" ;;
381 esac &&
382 +
383 + # Upstream URL and the primary branch tracking
384 git-repo-config remote."$origin".url "$repo" &&
385 git-repo-config remote."$origin".fetch \
386 "refs/heads/$head_points_at:$origin_track" &&
383 - (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
384 - while read dotslref
385 - do
386 - name=`expr "$dotslref" : './\(.*\)'`
387 - if test "z$head_points_at" = "z$name"
388 - then
389 - continue
390 - fi
391 - if test "$use_separate_remote" = '' &&
392 - test "z$origin" = "z$name"
393 - then
394 - continue
395 - fi
396 - git-repo-config remote."$origin".fetch "refs/heads/${name}:$remote_top/${name}" '^$'
397 - done &&
387 +
388 + # Set up the mappings to track the remaining branches.
389 + case "$use_separate_remote" in
390 + t)
391 + git-repo-config remote."$origin".fetch \
392 + "refs/heads/*:$remote_top/*" '^$'
393 + ;;
394 + *)
395 + (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
396 + while read dotslref
397 + do
398 + name=`expr "$dotslref" : './\(.*\)'`
399 + if test "z$head_points_at" = "z$name" ||
400 + test "z$origin" = "z$name"
401 + then
402 + continue
403 + fi
404 + git-repo-config remote."$origin".fetch \
405 + "refs/heads/${name}:$remote_top/${name}" '^$'
406 + done
407 + ;;
408 + esac &&
409 +
410 case "$use_separate_remote" in
411 t)
412 rm -f "refs/remotes/$origin/HEAD"
413 git-symbolic-ref "refs/remotes/$origin/HEAD" \
414 "refs/remotes/$origin/$head_points_at"
415 esac &&
416 +
417 git-repo-config branch."$head_points_at".remote "$origin" &&
418 git-repo-config branch."$head_points_at".merge "refs/heads/$head_points_at"
419 esac