Skip to content

Commit 6232f62

Browse files
torvaldsgitster
authored andcommitted
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>
1 parent 7c3fd25 commit 6232f62

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

builtin-fsck.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,20 +555,23 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
555555
return 0;
556556
}
557557

558+
static int is_branch(const char *refname)
559+
{
560+
return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
561+
}
562+
558563
static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
559564
{
560565
struct object *obj;
561566

562-
obj = lookup_object(sha1);
567+
obj = parse_object(sha1);
563568
if (!obj) {
564-
if (has_sha1_file(sha1)) {
565-
default_refs++;
566-
return 0; /* it is in a pack */
567-
}
568569
error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
569570
/* We'll continue with the rest despite the error.. */
570571
return 0;
571572
}
573+
if (obj->type != OBJ_COMMIT && is_branch(refname))
574+
error("%s: not a commit", refname);
572575
default_refs++;
573576
obj->used = 1;
574577
mark_reachable(obj, REACHABLE);

0 commit comments

Comments
 (0)