Skip to content

Commit 6762079

Browse files
Nanako Shiraishigitster
authored andcommitted
Cloning from a repo without "current branch"
If the remote repository does not have a "current branch", git-clone was confused and did not set up the resulting new repository correctly. It did not reset HEAD from the default 'master', and did not write the SHA1 to the master branch. Signed-off-by: Nanako Shiraishi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45fd8bd commit 6762079

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

git-clone.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,28 +377,34 @@ then
377377
)
378378
)
379379

380+
# Upstream URL
381+
git-config remote."$origin".url "$repo" &&
382+
383+
# Set up the mappings to track the remote branches.
384+
git-config remote."$origin".fetch \
385+
"+refs/heads/*:$remote_top/*" '^$' &&
386+
380387
# Write out remote.$origin config, and update our "$head_points_at".
381388
case "$head_points_at" in
382389
?*)
383390
# Local default branch
384391
git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
385392

386393
# Tracking branch for the primary branch at the remote.
387-
origin_track="$remote_top/$head_points_at" &&
388394
git-update-ref HEAD "$head_sha1" &&
389395

390-
# Upstream URL
391-
git-config remote."$origin".url "$repo" &&
392-
393-
# Set up the mappings to track the remote branches.
394-
git-config remote."$origin".fetch \
395-
"+refs/heads/*:$remote_top/*" '^$' &&
396396
rm -f "refs/remotes/$origin/HEAD"
397397
git-symbolic-ref "refs/remotes/$origin/HEAD" \
398398
"refs/remotes/$origin/$head_points_at" &&
399399

400400
git-config branch."$head_points_at".remote "$origin" &&
401401
git-config branch."$head_points_at".merge "refs/heads/$head_points_at"
402+
;;
403+
'')
404+
# Source had detached HEAD pointing nowhere
405+
git-update-ref --no-deref HEAD "$head_sha1" &&
406+
rm -f "refs/remotes/$origin/HEAD"
407+
;;
402408
esac
403409

404410
case "$no_checkout" in

0 commit comments

Comments
 (0)