Skip to content

Commit

Permalink
Make 'git fsck' complain about non-commit branches
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jan 16, 2008
1 parent 7c3fd25 commit 6232f62
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions builtin-fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,20 +555,23 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
return 0;
}

static int is_branch(const char *refname)
{
return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
}

static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *obj;

obj = lookup_object(sha1);
obj = parse_object(sha1);
if (!obj) {
if (has_sha1_file(sha1)) {
default_refs++;
return 0; /* it is in a pack */
}
error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
/* We'll continue with the rest despite the error.. */
return 0;
}
if (obj->type != OBJ_COMMIT && is_branch(refname))
error("%s: not a commit", refname);
default_refs++;
obj->used = 1;
mark_reachable(obj, REACHABLE);
Expand Down

0 comments on commit 6232f62

Please sign in to comment.