@matheusbsbs / matheus-bagliano / commits / 8eb2d0bee8
Fork 0

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>

Junio C Hamano committed Apr 11, 2007 at 01:28 UTC 8eb2d0bee8813ac37dc602d12b0abba632e96152
1 file changed +16 -8
builtin-fsck.c
+16 -8
@@ -532,7 +532,7 @@ static void get_default_heads(void)
532 * "show_unreachable" flag.
533 */
534 if (!default_refs) {
535 - error("No default references");
535 + fprintf(stderr, "notice: No default references\n");
536 show_unreachable = 0;
537 }
538 }
@@ -552,15 +552,23 @@ static int fsck_head_link(void)
552 {
553 unsigned char sha1[20];
554 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/"))
564 return error("HEAD points to something strange (%s)",
565 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 + }
572 return 0;
573 }
574