Skip to content

Dangling commits (after a force push) are not available, along with disscusion that was there

Summary

Typically after a rebase, amend or other action that requires a force push we can have dangled commits.

Such "dereferenced" commits are getting lost due to git gc that may be executed internally or by using GitLab Housekeeping features.

If it happens that there was a discussion attached to a specific commit - it is not available after dereferenced commit has been garbage-collected.

Commits are being recorded in push events and are available through system notes added to merge request, and currently this produces error 500 in GitLab.

Steps to reproduce

  • commit and push something to a branch
  • create a merge request
  • commit and push something again
  • write some comments on recent commit
  • amend this commit and force push
  • run GitLab Housekeeping feature
  • try to access this commit from a system note added after pushing it in a third step

Example: https://gitlab.com/gitlab-org/gitlab-ce/commit/694e5b4bd1cd0f4e6c40892d23a1af64d17c91b0

Expected behavior

GitLab should notify that "This commit has been removed" and show discussion that was there.

Relevant logs and/or screenshots

undefined method 'diffs' for nil:NilClass in app/controllers/projects/commit_controller.rb in define_show_vars at line 74

Sentry id: 1177

It looks like @project.commit(params[:id]) returns nil as this commit is no longer available in repository.

/cc @DouweM, @dzaporozhets