Renaming default branch leads to unreachable project settings page
## Summary After renaming the default branch I can't open the project settings page anymore. ## Steps to reproduce * You need a repository with some commits and one default branch - I'll call it _A_ in this example * Open a terminal and go to the path of the repo in your gitlab installation, i.e.`/home/git/repositories/$namespace/$repo.git/` * Rename the branch to _B_ by the following command: `git branch -m A B` * Open GitLab in your browser and navigate to the settings page of the project (i.e. `https://gitlab/$namespace/$repo/edit`) * Error 500 occurs ## Expected behavior The page of project settings occurs. I am notified that the default branch does not exist and can now change the default branch to `B`. ## Relevant logs and/or screenshots I think this shows the matching traceback: ``` Started GET "/uib/blocker/edit" for 127.0.0.1 at 2016-06-27 16:07:41 +0200 Processing by ProjectsController#edit as HTML Parameters: {"namespace_id"=>"uib", "id"=>"blocker"} Completed 500 Internal Server Error in 108ms (ActiveRecord: 2.5ms) ActionView::Template::Error (undefined method `sha' for nil:NilClass): 1: %fieldset.builds-feature 2: %h5.prepend-top-0 3: Builds 4: - unless @repository.gitlab_ci_yml 5: .form-group 6: %p Builds need to be configured before you can begin using Continuous Integration. 7: = link_to 'Get started with Builds', help_page_path('ci/quick_start ', 'README'), class: 'btn btn-info' app/models/repository.rb:525:in `head_tree' app/models/repository.rb:531:in `tree' app/models/repository.rb:511:in `gitlab_ci_yml' app/views/projects/_builds_settings.html.haml:4:in `_app_views_projects__builds_settings_html_haml__2780650300404000149_70213157900520' app/views/projects/edit.html.haml:89:in `block in _app_views_projects_edit_html_haml___2081903954413398376_70213163819340' app/views/projects/edit.html.haml:7:in `_app_views_projects_edit_html_haml___2081903954413398376_70213163819340' app/controllers/projects_controller.rb:24:in `edit' lib/gitlab/middleware/go.rb:16:in `call' ``` ## Output of checks ### Results of GitLab Application Check ``` Checking GitLab Shell ... GitLab Shell version >= 3.0.0 ? ... OK (3.0.0) Repo base directory exists? ... yes Repo base directory is a symlink? ... no Repo base owned by git:git? ... yes Repo base access is drwxrws---? ... yes hooks directories in repos are links: ... 6/3 ... ok 6/4 ... ok 6/6 ... ok 6/7 ... ok 2/8 ... ok 6/9 ... ok 6/12 ... ok 2/14 ... ok 2/15 ... ok 2/16 ... ok 2/17 ... ok 6/18 ... ok 2/20 ... ok 2/21 ... ok 2/23 ... ok 6/24 ... ok 2/28 ... ok 5/29 ... ok 11/31 ... ok 6/34 ... ok 6/35 ... ok 6/38 ... ok 6/39 ... ok 7/42 ... ok 2/43 ... ok 6/44 ... ok 5/45 ... ok 5/46 ... ok 6/47 ... ok 6/48 ... ok 5/50 ... ok 2/51 ... ok 6/52 ... ok 6/54 ... ok 5/55 ... ok 6/56 ... ok 2/63 ... ok 18/64 ... ok 18/65 ... ok 5/67 ... ok 5/68 ... ok 6/69 ... ok 7/70 ... ok 2/71 ... ok 18/72 ... ok 6/73 ... ok 6/78 ... ok 6/79 ... ok 6/80 ... ok 6/81 ... ok 18/83 ... ok 18/84 ... ok 2/85 ... ok 18/86 ... repository is empty 6/87 ... ok 6/88 ... ok 7/89 ... ok 6/90 ... ok 5/91 ... ok 6/93 ... ok 6/94 ... ok 6/95 ... repository is empty 18/96 ... ok 6/97 ... ok 6/98 ... ok 6/99 ... ok 6/100 ... ok 2/101 ... ok 2/103 ... ok 2/105 ... ok 6/106 ... ok 6/107 ... ok 6/114 ... ok 18/115 ... ok Running /home/git/gitlab-shell/bin/check Check GitLab API access: OK Check directories and files: /home/git/repositories/: OK /home/git/.ssh/authorized_keys: OK Send ping to redis server: gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking Reply by email ... Reply by email is disabled in config/gitlab.yml Checking Reply by email ... Finished Checking LDAP ... LDAP users with access to your GitLab server (only showing the first 100 results) [snip] Checking LDAP ... Finished Checking GitLab ... Git configured with autocrlf=input? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory setup correctly? ... yes Init script exists? ... yes Init script up-to-date? ... yes projects have namespace: ... 6/3 ... yes 6/4 ... yes 6/6 ... yes 6/7 ... yes 2/8 ... yes 6/9 ... yes 6/12 ... yes 2/14 ... yes 2/15 ... yes 2/16 ... yes 2/17 ... yes 6/18 ... yes 2/20 ... yes 2/21 ... yes 2/23 ... yes 6/24 ... yes 2/28 ... yes 5/29 ... yes 11/31 ... yes 6/34 ... yes 6/35 ... yes 6/38 ... yes 6/39 ... yes 7/42 ... yes 2/43 ... yes 6/44 ... yes 5/45 ... yes 5/46 ... yes 6/47 ... yes 6/48 ... yes 5/50 ... yes 2/51 ... yes 6/52 ... yes 6/54 ... yes 5/55 ... yes 6/56 ... yes 2/63 ... yes 18/64 ... yes 18/65 ... yes 5/67 ... yes 5/68 ... yes 6/69 ... yes 7/70 ... yes 2/71 ... yes 18/72 ... yes 6/73 ... yes 6/78 ... yes 6/79 ... yes 6/80 ... yes 6/81 ... yes 18/83 ... yes 18/84 ... yes 2/85 ... yes 18/86 ... yes 6/87 ... yes 6/88 ... yes 7/89 ... yes 6/90 ... yes 5/91 ... yes 6/93 ... yes 6/94 ... yes 6/95 ... yes 18/96 ... yes 6/97 ... yes 6/98 ... yes 6/99 ... yes 6/100 ... yes 2/101 ... yes 2/103 ... yes 2/105 ... yes 6/106 ... yes 6/107 ... yes 6/114 ... yes 18/115 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.1.0 ? ... yes (2.2.4) Your git bin path is "/usr/local/bin/git" Git version >= 2.7.3 ? ... yes (2.7.4) Active users: 14 Checking GitLab ... Finished ``` ### Results of GitLab Environment Info ``` System information System: Ubuntu 14.04 Current User: git Using RVM: no Ruby Version: 2.2.4p230 Gem Version: 2.4.5.1 Bundler Version:1.11.2 Rake Version: 10.5.0 Sidekiq Version:4.1.2 GitLab information Version: 8.9.1 Revision: c6da519 Directory: /home/git/gitlab DB Adapter: mysql2 URL: https://gitlab.uib.local HTTP Clone URL: https://gitlab.uib.local/some-group/some-project.git SSH Clone URL: git@gitlab.uib.local:some-group/some-project.git Using LDAP: yes Using Omniauth: no GitLab Shell Version: 3.0.0 Repositories: /home/git/repositories/ Hooks: /home/git/gitlab-shell/hooks/ Git: /usr/local/bin/git ```
issue