git-clone.sh: properly configure remote even if remote's head is dangling
When cloning a remote repository which's HEAD refers to a nonexistent ref, git-clone cloned all existing refs, but failed to write the configuration for 'remote'. Now it detects the dangling remote HEAD, refuses to checkout any local branch since HEAD refers to nowhere, but properly writes the configuration for 'remote', so that subsequent 'git fetch's don't fail. The problem was reported by Daniel Jacobowitz through http://bugs.debian.org/466581 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Gerrit Pape committed
Feb 20, 2008 at 15:10 UTC
5274ba6907cc12d6e6556ff85cb0e4819bd3f730
2 files changed
+21
-5
git-clone.sh
+13
-5
@@ -409,11 +409,12 @@ else
409
cd "$D" || exit
410
fi
411
412
-if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
412
+if test -z "$bare"
413
then
414
# a non-bare repository is always in separate-remote layout
415
remote_top="refs/remotes/$origin"
416
- head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
416
+ head_sha1=
417
+ test ! -r "$GIT_DIR/REMOTE_HEAD" || head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
418
case "$head_sha1" in
419
'ref: refs/'*)
420
# Uh-oh, the remote told us (http transport done against
@@ -470,9 +471,16 @@ then
471
git config branch."$head_points_at".merge "refs/heads/$head_points_at"
472
;;
473
'')
473
- # Source had detached HEAD pointing nowhere
474
- git update-ref --no-deref HEAD "$head_sha1" &&
475
- rm -f "refs/remotes/$origin/HEAD"
474
+ if test -z "$head_sha1"
475
+ then
476
+ # Source had nonexistent ref in HEAD
477
+ echo >&2 "Warning: Remote HEAD refers to nonexistent ref, unable to checkout."
478
+ no_checkout=t
479
+ else
480
+ # Source had detached HEAD pointing nowhere
481
+ git update-ref --no-deref HEAD "$head_sha1" &&
482
+ rm -f "refs/remotes/$origin/HEAD"
483
+ fi
484
;;
485
esac
486
t/t5701-clone-local.sh
+8
@@ -63,4 +63,12 @@ test_expect_success 'Even without -l, local will make a hardlink' '
63
test 0 = $copied
64
'
65
66
+test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
67
+ cd "$D" &&
68
+ echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
69
+ git clone a d &&
70
+ cd d &&
71
+ git fetch &&
72
+ test ! -e .git/refs/remotes/origin/HEAD'
73
+
74
test_done