elasticsearch indexing fails when no master in project

Summary

When indexing project for elasticsearch, some of them fail.

The failing repositories don't have master branch, and default_branch is set to other branch.

Steps to reproduce

  • create repository
  • create branch develop
  • change default_branch to develop
  • remove master

Example Project

We observe that on our self-hosted instance using version 11.11.3

What is the current bug behavior?

index task fails

What is the expected correct behavior?

default branch should be indexed.

Relevant logs and/or screenshots

sudo gitlab-rake gitlab:elastic:index_repositories ID_FROM=1234 ID_TO=1234
Indexing project repositories...I, [2019-06-27T14:17:50.767208 #9374]  INFO -- : Indexing Namespace / Project Name (ID=1234)...
W, [2019-06-27T14:17:52.215729 #9374]  WARN -- : /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/rugged-0.28.1/lib/rugged/repository.rb:22:in `head': reference 'refs/heads/master' not found (Rugged::ReferenceError)
        from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/rugged-0.28.1/lib/rugged/repository.rb:22:in `last_commit'
        from /opt/gitlab/embedded/service/gitlab-rails/ee/lib/elasticsearch/git/repository.rb:39:in `index_blobs'
        from /opt/gitlab/embedded/service/gitlab-rails/bin/elastic_repo_indexer:93:in `block in <main>'
        from /opt/gitlab/embedded/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
        from /opt/gitlab/embedded/service/gitlab-rails/bin/elastic_repo_indexer:91:in `<main>'

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
System information
System:         Ubuntu 18.04
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   2.5.3p105
Gem Version:    2.7.9
Bundler Version:1.17.3
Rake Version:   12.3.2
Redis Version:  3.2.12
Git Version:    2.21.0
Sidekiq Version:5.2.7
Go Version:     unknown

GitLab information Version: 11.11.3-ee Revision: 8c5c506955e Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 9.6.11 URL: https://gitlab.some.domain HTTP Clone URL: https://gitlab.some.domain/some-group/some-project.git SSH Clone URL: git@gitlab.some.domain:some-group/some-project.git Elasticsearch: yes Geo: no Using LDAP: yes Using Omniauth: yes Omniauth Providers: some_internal_oauth2

GitLab Shell Version: 9.1.0 Repository storage paths: default: /mnt/gitlab/data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git

Assignee Loading
Time tracking Loading