@matheusbsbs / matheus-bagliano / commits / 6232f62bc7
Fork 0

Make 'git fsck' complain about non-commit branches

Since having non-commits in branches is a no-no, and just means you cannot commit on them, let's make fsck tell you when a branch is bad. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jan 15, 2008 at 16:34 UTC 6232f62bc77ba9fc57fa97c61a7678a9f243c3bd
1 file changed +8 -5
builtin-fsck.c
+8 -5
@@ -555,20 +555,23 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
555 return 0;
556 }
557
558 +static int is_branch(const char *refname)
559 +{
560 + return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
561 +}
562 +
563 static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
564 {
565 struct object *obj;
566
562 - obj = lookup_object(sha1);
567 + obj = parse_object(sha1);
568 if (!obj) {
564 - if (has_sha1_file(sha1)) {
565 - default_refs++;
566 - return 0; /* it is in a pack */
567 - }
569 error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
570 /* We'll continue with the rest despite the error.. */
571 return 0;
572 }
573 + if (obj->type != OBJ_COMMIT && is_branch(refname))
574 + error("%s: not a commit", refname);
575 default_refs++;
576 obj->used = 1;
577 mark_reachable(obj, REACHABLE);