Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError (no implicit conversion of nil into Array) when creating a new project with auto repo init turned on #336

Closed
necramirez opened this issue Jan 28, 2015 · 35 comments
Assignees
Labels
Milestone

Comments

@necramirez
Copy link

  • Ruby: 2.0.0-p598
  • Redmine: 2.6.0.stable
  • Git: 1.7.1
  • redmine_git_hosting: v1.x branch

I have Automatically initialize Git repositories for new projects turned on, and I create a new project. I get this error in Redmine's production.log:

Started GET "/projects/new" for 9.187.62.249 at 2015-01-28 02:37:24 -0500
Processing by ProjectsController#new as HTML
  Current user: admin (id=1)
  Rendered projects/_form.html.erb (17.1ms)
  Rendered projects/new.html.erb within layouts/base (20.7ms)
Completed 200 OK in 50.6ms (Views: 36.2ms | ActiveRecord: 3.0ms)
Started POST "/projects" for 9.187.62.249 at 2015-01-28 02:37:41 -0500
Processing by ProjectsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"QUH8EX6l/0QCuL1j0jnR/tllhwGlnOrBMedkFJf4tJM=", "project"=>{"name"=>"Team Page", "description"=>"", "identifier"=>"team-page", "homepage"=>"", "is_public"=>"1", "parent_id"=>"", "inherit_members"=>"0", "enabled_module_names"=>["issue_tracking", "time_tracking", "files", "wiki", "repository", ""], "tracker_ids"=>["1", "2", ""], "issue_custom_field_ids"=>[""]}, "commit"=>"Create"}
  Current user: admin (id=1)
Redirected to http://localhost/projects/team-page/settings
Completed 500 Internal Server Error in 1420.5ms

TypeError (no implicit conversion of nil into Array):
  lib/redmine/scm/adapters/git_adapter.rb:85:in `branches'
  app/models/repository/git.rb:75:in `branches'
  app/models/repository/git.rb:130:in `fetch_changesets'

NOTE: This also happens when Automatically initialize Git repositories for new projects is turned off, then I create the project, then try to create the repository.

@necramirez
Copy link
Author

I checked ~git/repositories/ and the repository was still created.

I can still go to the project's Settings -> Repositories without any error. However, when I try to Edit the repository, I see this error in the Redmine logs:

Started GET "/repositories/19/edit" for 9.187.68.222 at 2015-01-28 03:48:45 -0500
Processing by RepositoriesController#edit as HTML
  Parameters: {"id"=>"19"}
  Current user: admin (id=1)
  Rendered plugins/redmine_git_hosting/app/views/common/_git_urls.html.erb (6.3ms)
  Rendered plugins/redmine_git_hosting/app/views/repositories/_edit_top.html.haml (6.7ms)
  Rendered repositories/_form.html.erb (2.8ms)
  Rendered plugins/redmine_git_hosting/app/views/repositories/_xitolite_options.html.haml (4.2ms)
  Rendered plugins/redmine_git_hosting/app/views/repositories/edit.html.haml within layouts/base (16.5ms)
Completed 500 Internal Server Error in 24.6ms

ActionView::Template::Error (no implicit conversion of nil into Array):
    35: 
    36:               %p
    37:                 = label_tag 'repository_git_extra[default_branch]', l(:label_repository_default_branch)
    38:                 - if !repository.branches.empty?
    39:                   = f.select :default_branch, repository_branches_list(repository.branches)
    40:                 - else
    41:                   %span{ class: 'label label-info' }= repository.default_branch
  lib/redmine/scm/adapters/git_adapter.rb:85:in `branches'
  app/models/repository/git.rb:75:in `branches'

There is also an error when I try to view that repo.

@necramirez
Copy link
Author

Here's what I see in git_hosting.log, when I create the repository with Initialize this repository with a README unchecked:

2015-01-28 04:08:51 -0500 [INFO] User 'admin' created a new repository 'team-page'
2015-01-28 04:08:51 -0500 [INFO] Accessing gitolite-admin.git at '/tmp/redmine_git_hosting/git/gitolite-admin.git'
2015-01-28 04:08:51 -0500 [INFO] add_repository : repository 'team-page' does not exist in Gitolite, create it ...
2015-01-28 04:08:51 -0500 [DEBUG] add_repository : repository path 'repositories/team-page.git'
2015-01-28 04:08:51 -0500 [INFO] add_repository : commiting to Gitolite...
2015-01-28 04:08:51 -0500 [DEBUG] Non-zero exit code pid 8605 exit 1 for `sudo -n -u git -i find /home/git/recycle_bin/ -type d -regex /home/git/recycle_bin/[0-9]+__team-page.git -prune -print`
2015-01-28 04:08:51 -0500 [INFO] add_repository : let Gitolite create empty repository 'repositories/team-page.git'
2015-01-28 04:08:52 -0500 [INFO] Execute Gitolite Plugins

And here's the log when it's checked:

2015-01-28 04:11:47 -0500 [INFO] User 'admin' created a new repository 'team-page'
2015-01-28 04:11:47 -0500 [INFO] Accessing gitolite-admin.git at '/tmp/redmine_git_hosting/git/gitolite-admin.git'
2015-01-28 04:11:48 -0500 [INFO] add_repository : repository 'team-page' does not exist in Gitolite, create it ...
2015-01-28 04:11:48 -0500 [DEBUG] add_repository : repository path 'repositories/team-page.git'
2015-01-28 04:11:48 -0500 [INFO] add_repository : commiting to Gitolite...
2015-01-28 04:11:48 -0500 [DEBUG] Non-zero exit code pid 12282 exit 1 for `sudo -n -u git -i find /home/git/recycle_bin/ -type d -regex /home/git/recycle_bin/[0-9]+__team-page.git -prune -print`
2015-01-28 04:11:48 -0500 [INFO] add_repository : let Gitolite create empty repository 'repositories/team-page.git'
2015-01-28 04:11:48 -0500 [INFO] Execute Gitolite Plugins
2015-01-28 04:11:49 -0500 [INFO] Create README file for repository 'team-page'
2015-01-28 04:11:49 -0500 [ERROR] Error while creating README file for repository 'team-page'
2015-01-28 04:11:49 -0500 [ERROR] Early EOF

@necramirez
Copy link
Author

I also tried to manually fetch changesets using the rake task:

[redmine@xxx redmine]$ bundle exec rake redmine_git_hosting:fetch_changesets RAILS_ENV=production --trace
** Invoke redmine_git_hosting:fetch_changesets (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute redmine_git_hosting:fetch_changesets
Performing manual fetch_changesets operation...
rake aborted!
TypeError: no implicit conversion of nil into Array
/home/redmine/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/patches/xitolite_adapter_patch.rb:195:in `concat'
/home/redmine/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/patches/xitolite_adapter_patch.rb:195:in `base_args'
/home/redmine/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/patches/xitolite_adapter_patch.rb:174:in `prepare_command'
/home/redmine/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/patches/xitolite_adapter_patch.rb:161:in `git_cmd_with_git_hosting'
/home/redmine/redmine/lib/redmine/scm/adapters/git_adapter.rb:85:in `branches'
/home/redmine/redmine/app/models/repository/git.rb:75:in `branches'
/home/redmine/redmine/app/models/repository/git.rb:130:in `fetch_changesets'
/home/redmine/redmine/app/models/repository.rb:342:in `block (2 levels) in fetch_changesets'
/home/redmine/.rvm/gems/[email protected]/gems/activerecord-3.2.19/lib/active_record/associations/collection_proxy.rb:91:in `each'
/home/redmine/.rvm/gems/[email protected]/gems/activerecord-3.2.19/lib/active_record/associations/collection_proxy.rb:91:in `method_missing'
/home/redmine/redmine/app/models/repository.rb:340:in `block in fetch_changesets'
/home/redmine/redmine/app/models/repository.rb:339:in `each'
/home/redmine/redmine/app/models/repository.rb:339:in `fetch_changesets'
/home/redmine/redmine/plugins/redmine_git_hosting/lib/tasks/redmine_git_hosting.rake:35:in `block (2 levels) in <top (required)>'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/redmine/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/redmine/.rvm/gems/[email protected]/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/redmine/.rvm/gems/[email protected]/bin/rake:23:in `load'
/home/redmine/.rvm/gems/[email protected]/bin/rake:23:in `<main>'
/home/redmine/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval'
/home/redmine/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => redmine_git_hosting:fetch_changesets

@n-rodriguez n-rodriguez self-assigned this Jan 29, 2015
@n-rodriguez n-rodriguez added this to the 1.0.1 milestone Jan 29, 2015
@n-rodriguez
Copy link
Contributor

Actually there are 2 bugs here :

first one : README file is not created :

2015-01-28 04:11:49 -0500 [INFO] Create README file for repository 'team-page'
2015-01-28 04:11:49 -0500 [ERROR] Error while creating README file for repository 'team-page'

Solution : https://jbox-web.github.io/redmine_git_hosting/configuration/troubleshooting/#initialization-of-the-repo-with-readme-file-does-not-work

second :

ActionView::Template::Error (no implicit conversion of nil into Array):
    35: 
    36:               %p
    37:                 = label_tag 'repository_git_extra[default_branch]', l(:label_repository_default_branch)
    38:                 - if !repository.branches.empty?
    39:                   = f.select :default_branch, repository_branches_list(repository.branches)
    40:                 - else
    41:                   %span{ class: 'label label-info' }= repository.default_branch
  lib/redmine/scm/adapters/git_adapter.rb:85:in `branches'
  app/models/repository/git.rb:75:in `branches'

The repository is empty : no branches here. (I should test for nil before)

@necramirez
Copy link
Author

Ok, so the first one is a different bug altogether. Let me open a new issue for that: #338

@necramirez
Copy link
Author

The second one, I traced a bit and found that the command to get branches didn't get anything. I pushed something, so master now exists in that repo, but I still get the error.

Then I stumbled upon you Development Guide (https://jbox-web.github.io/redmine_git_hosting/guide/development/) and saw that you had Git 1.9.1, while I only had 1.7.1

I then upgraded my Git, and it now works! This means that redmine_git_hosting needs a minimum Git version that's higher than 1.7.1 -- which isn't stated anywhere in the docs.

@n-rodriguez
Copy link
Contributor

Thank you!

@necramirez
Copy link
Author

I guess we can close this now, since the nil case won't happen with the correct Git version, right? The empty repo page should show up?

@n-rodriguez
Copy link
Contributor

I guess we can close this now, since the nil case won't happen with the correct Git version, right?

Yes, but I need to be sure.

The empty repo page should show up?

Yes

@n-rodriguez
Copy link
Contributor

Btw I've just added a warning in Config Check for Git version < 1.8.5 : ec11e79

@n-rodriguez
Copy link
Contributor

Fixed in Redmine trunk : http://www.redmine.org/projects/redmine/repository/revisions/13927/diff/trunk/lib/redmine/scm/adapters/git_adapter.rb but maybe I should monkey patch this method to avoid nil...

@n-rodriguez
Copy link
Contributor

Can you please test with the monkey-patch-branch?

@n-rodriguez
Copy link
Contributor

A very good point for you!! It does need a quiet recent version of Git, I forgot this point.
Actually it needs a Git version that provides the -C argument.

I think I should go to bed... It's not that... We don't use the -C argument but --git-dir (https://github.com/jbox-web/redmine_git_hosting/blob/devel/lib/redmine_git_hosting/commands/git.rb#L101). (I use the -C on another project which also uses Git repositories but nothing to do with Redmine Git Hosting...)

@necramirez
Copy link
Author

  1. delete my repo
  2. clear recycle bin
  3. create new repo, DID NOT auto init with README -- repo is created in gitolite side
  4. I go to project's Repository tab, but get a 404
The entry or revision was not found in the repository.

I tried to Resync all projects and Flush Git cache, but I still get the 404, not the empty repo page.

I pushed from my local, so master is now in gitolite, and the repo page now gives a 500 error. production.log says:

Started GET "/projects/team-page/repository" for 9.187.68.222 at 2015-01-28 23:12:53 -0500
Processing by RepositoriesController#show as HTML
  Parameters: {"id"=>"team-page"}
  Current user: admin (id=1)
SCM command failed, make sure that your SCM command (e.g. svn) is in PATH (/home/redmine/.rvm/gems/[email protected]/bin:/home/redmine/.rvm/gems/ruby-2.0.0-p598@global/bin:/home/redmine/.rvm/rubies/ruby-2.0.0-p598/bin:/usr/lib64/qt-3.3/bin:/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/home/redmine/.rvm/bin:/home/redmine/bin)
You can configure your scm commands in config/configuration.yml.
'sudo' '-n' '-u' 'git' '-i' 'git' '--git-dir' 'repositories/team-page.git' '-c' 'core.quotepath=false' '-c' 'log.decorate=no' 'branch' '--no-color' '--verbose' '--no-abbrev'
with: uninitialized constant RedmineGitHosting::Patches::XitoliteAdapterPatch::InstanceMethods::GitBranch
Completed 500 Internal Server Error in 153.7ms

NameError (uninitialized constant RedmineGitHosting::Patches::XitoliteAdapterPatch::InstanceMethods::ScmCommandAborted):
  app/models/repository/git.rb:75:in `branches'
  app/controllers/repositories_controller.rb:326:in `find_project_repository'

To address SCM command failed, I explicitly specified in <redmine root>/config/configuration.yml:

  scm_git_command: /usr/bin/git

to no avail.

@n-rodriguez
Copy link
Contributor

I pushed from my local, so master is now in gitolite, and the repo page now gives a 500 error. production.log says:

Actually it's worse than that... I don't completly understand the Ruby inheritance mechanism...
XitoliteAdapter inherits from GitAdapter but some classes which are define directly in GitAdapter are not inherited (GitBranch, ScmCommandAborted and maybe others) hence the NameError exception.

To fix this I had to reimplement the whole GitAdapter class in XitoliteAdapter... I wanted to avoid that to avoid code duplication but it seems to be the only way...

This has revealed an other issue in RepositoryController with the find_project_repository method wich render 404 error if no branch are found. I've monkey patched the method to render Git instructions.

Now it works with Git 1.7.10 :)

@necramirez
Copy link
Author

Which branch should I test now? :)

@n-rodriguez
Copy link
Contributor

You can do a git pull on monkey-patch-branch

@n-rodriguez
Copy link
Contributor

I then upgraded my Git, and it now works! This means that redmine_git_hosting needs a minimum Git version that's higher than 1.7.1 -- which isn't stated anywhere in the docs.

I've reverted the doc but it was already here : https://jbox-web.github.io/redmine_git_hosting/download/index.html ;)

@necramirez
Copy link
Author

Both the 404 and 500 are gone! However, I still see the empty repo page, despite having pushed master already. I had to do a manual bundle exec rake redmine_git_hosting:fetch_changesets RAILS_ENV=production --trace before the code appeared in the repo page. This despite having cache disabled for redmine_git_hosting.

@n-rodriguez
Copy link
Contributor

Check your Hook url in plugin settings

@n-rodriguez
Copy link
Contributor

I've merged the patch in devel and v1.x branches so you can switch back to v1.x

@necramirez
Copy link
Author

What value should I assign to Hooks URL?

I have mine as the Redmine root URL, with https:// (e.g. https://my.server.com ). The Hooks tab now shows Hooks URL as https://my.server.com/githooks/post-receive/redmine and Hooks Git namespace as redminegitolite

@n-rodriguez
Copy link
Contributor

I have mine as the Redmine root URL, with https:// (e.g. https://my.server.com ). The Hooks tab now shows Hooks URL as https://my.server.com/githooks/post-receive/redmine and Hooks Git namespace as redminegitolite

That should be fine.

@necramirez
Copy link
Author

Will there be any issues with an untrusted SSL cert/CA for HTTPS Hooks URLs (we have a company-internal CA)?

@necramirez
Copy link
Author

My Hooks URL isn't being hit at all, looking at ~git/.gitolite/logs/gitolite-*.log..

@n-rodriguez
Copy link
Contributor

My Hooks URL isn't being hit at all, looking at ~git/.gitolite/logs/gitolite-*.log..

You won't see it here but in <redmine root>/log/git_hosting.log.

@necramirez
Copy link
Author

There's also nothing logged in git_hosting.log

@necramirez
Copy link
Author

Just to add, I'm not seeing the Notifying Redmine about changes to this repository message when I push from my local. Looks like the post-update hook really isn't being triggered.

I have Ruby 1.8.7 installed globally on my server, so it's available to the git user:

[git@xxx ~]$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

@necramirez
Copy link
Author

I've also executed this manually:

gitolite setup --hooks-only

but still, nothing is happening.

What else can I check?

@necramirez
Copy link
Author

I see something new!

The repo isn't updated in Redmine only for the initial push.

  1. Create new project/repo -- repo is empty
  2. I see the empty repo page
  3. I do the initial push from my local
  4. I still see the empty repo page
  5. I manually run the rake task fetch_changesets
  6. Repo page is now updated
  7. I make a new commit and push
  8. Repo page is updated immediately

@necramirez
Copy link
Author

My current workaround is I added a cron job to run the fetch_changesets rake task every 15 minutes.

Will wait for your feedback.

@n-rodriguez
Copy link
Contributor

in <git user home>/.gitolite.rc file be sure to have enabled LOCAL code like this :

LOCAL_CODE  =>  "$ENV{HOME}/local"

@necramirez
Copy link
Author

BTW, that's not in the How To Install page. :-p

I updated my .gitolite.rc with that, but it didn't fix my issue.

@n-rodriguez
Copy link
Contributor

BTW, that's not in the How To Install page. :-p

You're right. I'm gonna update the doc.

@necramirez
Copy link
Author

Anyway, the original issue has already been fixed, so I think we can close this already (oh, it's already closed :-p)? I will create a new issue for this initial push problem I'm experiencing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants