Skip to content

Gracefully handle corrupted/invalid repo HEAD

What does this MR do and why?

Closes #432019 (closed)

Problem

If the repository is corrupted and the default branch points to a missing commit, then it is not possible to see any information about the project.

Solution

Handle an exception on project page and display a helpful error message.

Screenshots or screen recordings

Screenshot_2023-12-01_at_11.53.27

How to set up and validate locally

  1. Create a new project with a README file
  2. In Rails console execute and get a path to the repository
> Project.last.repository
=> #<Repository:@hashed/8e/61/8e612bd1f5d132a339575b8dafb7842c64614e56bcf3d5ab65a0bc4b34329407>
  1. From GDK folder execute (use the path from step 2 + ".git" at the end)
cd gitlab-development-kit
praefect -config gitaly/praefect.config.toml  metadata  -virtual-storage default -relative-path @hashed/8e/61/8e612bd1f5d132a339575b8dafb7842c64614e56bcf3d5ab65a0bc4b34329407.git

Example response

...
Replica Path: "@cluster/repositories/fc/72/415"
...
  1. Go to replica path folder
cd repositories/@cluster/repositories/fc/72/415
  1. Break the default branch of the repository
echo "aaa" > refs/heads/main
  1. Drop repository caches in Rails console Project.last.repository.expire_all_method_caches
  2. Visit the project page, it should be broken

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports