Skip to content

Commit 61dde8f

Browse files
author
Junio C Hamano
committed
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>
1 parent b1bfcae commit 61dde8f

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

git-clone.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,41 +366,54 @@ then
366366
)
367367
)
368368

369-
# Write out remotes/$origin file, and update our "$head_points_at".
369+
# Write out remote.$origin config, and update our "$head_points_at".
370370
case "$head_points_at" in
371371
?*)
372-
mkdir -p "$GIT_DIR/remotes" &&
372+
# Local default branch
373373
git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
374+
375+
# Tracking branch for the primary branch at the remote.
374376
case "$use_separate_remote" in
375377
t) origin_track="$remote_top/$head_points_at"
376378
git-update-ref HEAD "$head_sha1" ;;
377379
*) origin_track="$remote_top/$origin"
378380
git-update-ref "refs/heads/$origin" "$head_sha1" ;;
379381
esac &&
382+
383+
# Upstream URL and the primary branch tracking
380384
git-repo-config remote."$origin".url "$repo" &&
381385
git-repo-config remote."$origin".fetch \
382386
"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+
398410
case "$use_separate_remote" in
399411
t)
400412
rm -f "refs/remotes/$origin/HEAD"
401413
git-symbolic-ref "refs/remotes/$origin/HEAD" \
402414
"refs/remotes/$origin/$head_points_at"
403415
esac &&
416+
404417
git-repo-config branch."$head_points_at".remote "$origin" &&
405418
git-repo-config branch."$head_points_at".merge "refs/heads/$head_points_at"
406419
esac

0 commit comments

Comments
 (0)