refs/files: improve error handling when verifying symrefs
The error handling when verifying symbolic refs is a bit on the wild side: - `fsck_report_ref()` can be told to ignore specific errors. If an error has been ignored and a previous check raised an unignored error, then assigning `ret = fsck_report_ref()` will cause us to swallow the previous error. - When the target reference is not valid we bail out early without checking for other errors. Fix both of these issues by consistently or'ing the return value and not bailing out early. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jan 12, 2026 at 10:02 UTC
9ebccf744a967f399579a3f3ffbeb40120f5a1e1
1 file changed
+13
-15
refs/files-backend.c
+13
-15
@@ -3737,17 +3737,15 @@ static int files_fsck_symref_target(struct fsck_options *o,
3737
if (!is_referent_root &&
3738
!starts_with(referent->buf, "refs/") &&
3739
!starts_with(referent->buf, "worktrees/")) {
3740
- ret = fsck_report_ref(o, report,
3741
- FSCK_MSG_SYMREF_TARGET_IS_NOT_A_REF,
3742
- "points to non-ref target '%s'", referent->buf);
3743
-
3740
+ ret |= fsck_report_ref(o, report,
3741
+ FSCK_MSG_SYMREF_TARGET_IS_NOT_A_REF,
3742
+ "points to non-ref target '%s'", referent->buf);
3743
}
3744
3745
if (!is_referent_root && check_refname_format(referent->buf, 0)) {
3747
- ret = fsck_report_ref(o, report,
3748
- FSCK_MSG_BAD_REFERENT_NAME,
3749
- "points to invalid refname '%s'", referent->buf);
3750
- goto out;
3746
+ ret |= fsck_report_ref(o, report,
3747
+ FSCK_MSG_BAD_REFERENT_NAME,
3748
+ "points to invalid refname '%s'", referent->buf);
3749
}
3750
3751
if (symbolic_link)
@@ -3755,19 +3753,19 @@ static int files_fsck_symref_target(struct fsck_options *o,
3753
3754
if (referent->len == orig_len ||
3755
(referent->len < orig_len && orig_last_byte != '\n')) {
3758
- ret = fsck_report_ref(o, report,
3759
- FSCK_MSG_REF_MISSING_NEWLINE,
3760
- "misses LF at the end");
3756
+ ret |= fsck_report_ref(o, report,
3757
+ FSCK_MSG_REF_MISSING_NEWLINE,
3758
+ "misses LF at the end");
3759
}
3760
3761
if (referent->len != orig_len && referent->len != orig_len - 1) {
3764
- ret = fsck_report_ref(o, report,
3765
- FSCK_MSG_TRAILING_REF_CONTENT,
3766
- "has trailing whitespaces or newlines");
3762
+ ret |= fsck_report_ref(o, report,
3763
+ FSCK_MSG_TRAILING_REF_CONTENT,
3764
+ "has trailing whitespaces or newlines");
3765
}
3766
3767
out:
3770
- return ret;
3768
+ return ret ? -1 : 0;
3769
}
3770
3771
static int files_fsck_refs_content(struct ref_store *ref_store,