Skip to content

Handle clone situations where HEAD is invalid

Administrator requested to merge 116-fix-weird-repo-state into main

Created by: flying-robot

In some situations, it appears that empty repos may wind up with a truncated HEAD file on disk for reasons unknown. That breaks the repositories view (among other things), and is not easily recoverable within the Sourcegraph application (fixing the repository or deleting it and re-cloning are the current suggestions).

To begin addressing that, this PR:

  1. Introduces an ensureHead function that will create a HEAD file with a default if the file is absent or blank.
  2. Introduces a testRepoCorrupter that tests can use to inject repo-level faults.
  3. Adds a number of tests to verify the overall clone behavior with and without protections.

I wasn't able to trick git into cloning a repo that was truly busted, so I opted instead for fault injection. The repo is checked out to a temporary location first, and alongside the bad ref cleanup it will check HEAD presence and try to take a compensating action if necessary.

fixes https://github.com/sourcegraph/customer/issues/116

Merge request reports

Loading