static int files_fsck_refs_name(struct ref_store *ref_store UNUSED,
struct fsck_options *o,
const char *refname,
- const char *path,
+ const char *path UNUSED,
int mode UNUSED)
{
struct strbuf sb = STRBUF_INIT;
- const char *filename;
int ret = 0;
- filename = basename((char *) path);
-
- /*
- * Ignore the files ending with ".lock" as they may be lock files
- * However, do not allow bare ".lock" files.
- */
- if (filename[0] != '.' && ends_with(filename, ".lock"))
- goto cleanup;
-
if (is_root_ref(refname))
goto cleanup;
struct strbuf refname = STRBUF_INIT;
struct strbuf sb = STRBUF_INIT;
struct dir_iterator *iter;
+ const char *filename;
int iter_status;
int ret = 0;
strbuf_addf(&refname, "worktrees/%s/", wt->id);
strbuf_addf(&refname, "refs/%s", iter->relative_path);
+ filename = basename((char *) iter->path.buf);
+
+ /*
+ * Ignore the files ending with ".lock" as they may be lock files.
+ * However, do not skip invalid refnames with '.lock' suffix.
+ */
+ if (filename[0] != '.' && ends_with(filename, ".lock"))
+ continue;
+
if (files_fsck_ref(ref_store, o, refname.buf,
iter->path.buf, iter->st.st_mode) < 0)
ret = -1;
)
'
+test_expect_success 'lock files should be ignored' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ git commit --allow-empty -m initial &&
+ git checkout -b branch-1 &&
+
+ touch .git/refs/heads/branch-1.lock &&
+ git refs verify 2>err &&
+ test_must_be_empty err &&
+
+ echo "foobar" >.git/refs/heads/branch-2 &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/branch-2: badRefContent: foobar
+ EOF
+ test_cmp expect err
+ )
+'
+
+test_expect_success 'bare lock files should not be ignored' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ git commit --allow-empty -m initial &&
+ git checkout -b branch-1 &&
+
+ # invalid refname should be reported
+ cp .git/refs/heads/branch-1 .git/refs/heads/.branch-1.lock &&
+ # invalid refname and content should be reported
+ touch .git/refs/heads/.lock &&
+
+ test_must_fail git refs verify 2>err &&
+ test_grep "error: refs/heads/.branch-1.lock: badRefName: invalid refname format" err &&
+ test_grep "error: refs/heads/.lock: badRefName: invalid refname format" err &&
+ test_grep "error: refs/heads/.lock: badRefContent: " err
+ )
+'
+
test_expect_success 'ref name check should be adapted into fsck messages' '
test_when_finished "rm -rf repo" &&
git init repo &&