]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-fsck.c
Merge commit 'jc/maint' into gfi-maint
[thirdparty/git.git] / builtin-fsck.c
index b8e71b640b66ebd95a436a5c1c7f3fce0647be0c..7c3b0a535f81a350d11df112a6a5b5a49b139afb 100644 (file)
@@ -227,8 +227,7 @@ static int fsck_tree(struct tree *item)
        const char *o_name;
        const unsigned char *o_sha1;
 
-       desc.buf = item->buffer;
-       desc.size = item->size;
+       init_tree_desc(&desc, item->buffer, item->size);
 
        o_mode = 0;
        o_name = NULL;
@@ -242,7 +241,7 @@ static int fsck_tree(struct tree *item)
 
                if (strchr(name, '/'))
                        has_full_path = 1;
-               has_zero_pad |= *(char *)desc.buf == '0';
+               has_zero_pad |= *(char *)desc.buffer == '0';
                update_tree_entry(&desc);
 
                switch (mode) {
@@ -533,7 +532,7 @@ static void get_default_heads(void)
         * "show_unreachable" flag.
         */
        if (!default_refs) {
-               error("No default references");
+               fprintf(stderr, "notice: No default references\n");
                show_unreachable = 0;
        }
 }
@@ -553,15 +552,23 @@ static int fsck_head_link(void)
 {
        unsigned char sha1[20];
        int flag;
-       const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag);
-
-       if (!head_points_at || !(flag & REF_ISSYMREF))
-               return error("HEAD is not a symbolic ref");
-       if (prefixcmp(head_points_at, "refs/heads/"))
+       int null_is_error = 0;
+       const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
+
+       if (!head_points_at)
+               return error("Invalid HEAD");
+       if (!strcmp(head_points_at, "HEAD"))
+               /* detached HEAD */
+               null_is_error = 1;
+       else if (prefixcmp(head_points_at, "refs/heads/"))
                return error("HEAD points to something strange (%s)",
                             head_points_at);
-       if (is_null_sha1(sha1))
-               return error("HEAD: not a valid git pointer");
+       if (is_null_sha1(sha1)) {
+               if (null_is_error)
+                       return error("HEAD: detached HEAD points at nothing");
+               fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
+                       head_points_at + 11);
+       }
        return 0;
 }