ref: Return FailedPrecondition when DeleteRefs hits a file-directory conflict
What
DeleteRefs now returns FailedPrecondition instead of Internal when git update-ref refuses the batch because of a file-directory conflict (refs/foo exists, so git will not touch refs/foo/bar). The error carries a new DeleteRefsError.reference_conflict detail, a ReferenceConflictError with existing_reference_name and conflicting_reference_name, so callers need not parse the message. The message is unchanged.
Why
delete_refs.go maps a locked reference or packed-refs file to Aborted, but every other prepare failure to Internal. The updater already types this one as FileDirectoryConflictError (since !9326 (merged)); only the mapping was missing. The repository's state forbids the request and sending it again unchanged cannot succeed, so it is not a Gitaly fault, yet as Internal it counts against the server error SLI.
On GitLab.com this is about 20,000 Internal errors a day for this RPC (5,046 in a 6 h window), all from one Sidekiq worker retrying one batch every minute, on two repositories on two production nodes. Telemetry covers GitLab.com only; self-managed and Dedicated are not measured.
ReferenceExistsError is not reused: it means a reference that ought not to exist does, the opposite case.
Tracker issue: gitlab-com/gl-infra/sandbox/gitaly-sre-flow#79 (confidential).
Effect and what it does not do
This moves the signature from Internal to FailedPrecondition; it does not repair the repositories, and the worker still retries. A client that does not know the new detail treats it as a generic failure of the call, as today. The repair and a back-off belong to the Rails worker and are a separate change once a gitaly gem carries this proto.
Testing
New TestDeleteRefs_referenceConflict packs refs/merge-requests/1, deletes refs/merge-requests/1/head, and expects the typed error and the existing reference left in place. Without the handler change it fails (Internal, no detail). With it, WITH_BUNDLED_GIT=YesPlease TEST_PACKAGES=./internal/gitaly/service/ref TEST_OPTIONS='-count=1 -run=TestDeleteRefs' make test passes, 18 tests, including TestDeleteRefs_refLocked and TestDeleteRefs_packedRefsLocked (still Aborted). make proto was run and the generated code is committed. Also run, no failures: the whole ref/... and git/updateref/... packages (388 tests) and GITALY_TEST_REF_FORMAT=reftable for TestDeleteRefs (18 tests). Not run: test-with-praefect, test-with-mvcc, make lint, make verify.
Changelog: fixed