Skip to content

Commit 8eb2d0b

Browse files
author
Junio C Hamano
committed
fsck: do not complain on detached HEAD.
Detached HEAD is just a normal state of a repository. Do not say anything about it. Do not give worrying "error:" messages when we let the user know that the HEAD points at nothing (i.e. yet to be born branch), nor we do not have any default refs to start following the objects chain. Reword them as "notice:". Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f981577 commit 8eb2d0b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

builtin-fsck.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static void get_default_heads(void)
532532
* "show_unreachable" flag.
533533
*/
534534
if (!default_refs) {
535-
error("No default references");
535+
fprintf(stderr, "notice: No default references\n");
536536
show_unreachable = 0;
537537
}
538538
}
@@ -552,15 +552,23 @@ static int fsck_head_link(void)
552552
{
553553
unsigned char sha1[20];
554554
int flag;
555-
const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag);
556-
557-
if (!head_points_at || !(flag & REF_ISSYMREF))
558-
return error("HEAD is not a symbolic ref");
559-
if (prefixcmp(head_points_at, "refs/heads/"))
555+
int null_is_error = 0;
556+
const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
557+
558+
if (!head_points_at)
559+
return error("Invalid HEAD");
560+
if (!strcmp(head_points_at, "HEAD"))
561+
/* detached HEAD */
562+
null_is_error = 1;
563+
else if (prefixcmp(head_points_at, "refs/heads/"))
560564
return error("HEAD points to something strange (%s)",
561565
head_points_at);
562-
if (is_null_sha1(sha1))
563-
return error("HEAD: not a valid git pointer");
566+
if (is_null_sha1(sha1)) {
567+
if (null_is_error)
568+
return error("HEAD: detached HEAD points at nothing");
569+
fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
570+
head_points_at + 11);
571+
}
564572
return 0;
565573
}
566574

0 commit comments

Comments
 (0)