Re: [PATCH] fsck: detect bare repos in trees and warn
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 7, 2022, 15:20 UTC
- Message-ID
- <xmqqzgkwudh6.fsf@gitster.g>
- In-Reply-To
- <20220406232231.47714-1-chooglen@google.com>
Glen Choo <chooglen@google.com> writes:
Show 8 quoted lines
> @@ -602,6 +605,12 @@ static int fsck_tree(const struct object_id *tree_oid, > has_dotdot |= !strcmp(name, ".."); > has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name); > has_zero_pad |= *(char *)desc.buffer == '0'; > + has_head |= !strcasecmp(name, "HEAD") > + && (S_ISLNK(mode) || S_ISREG(mode)); > + has_refs_entry |= !strcasecmp(name, "refs") > + && (S_ISLNK(mode) || S_ISDIR(mode));
Sorry, I know I am to blame, but I think it is wrong to insist "refs" (and others) to be a directory. setup.c::is_git_directory() only checks with access(X_OK). Also, if I am not mistaken, we plan to take advantage of it and may make refs a regular file, for example, to signal that the ref-files backend is unwelcome in the repository. HEAD can be a symbolic link, not necessarily a regular file. We do not create "refs" and "objects" as symbolic links ourselves, but it is good to see that the code protects us against such a directory with these entries being one.
Show 21 quoted lines
> + has_objects_entry |= !strcasecmp(name, "objects")
> + && (S_ISLNK(mode) || S_ISDIR(mode));
>
> if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
> if (!S_ISLNK(mode))
> @@ -739,6 +748,16 @@ static int fsck_tree(const struct object_id *tree_oid,
> retval += report(options, tree_oid, OBJ_TREE,
> FSCK_MSG_TREE_NOT_SORTED,
> "not properly sorted");
> + /*
> + * Determine if this tree looks like a bare repository according
> + * to the rules of setup.c. If those are changed, this should be
> + * changed too.
> + */
> + if (has_head && has_refs_entry && has_objects_entry)
> + retval += report(options, tree_oid, OBJ_TREE,
> + FSCK_MSG_EMBEDDED_BARE_REPO,
> + "contains bare repository");
> +
> return retval;
> }