Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #4299

Closed
Open
Created Jun 13, 2013 by Administrator@rootOwner

Gitlab doesn't execute git during merge_action with environment PATH and GEM_PATH

Created by: pspoerri

  1. Summary PATH and GEM_PATH are not forwarded to git commands on merge request. Thus producing a failure in the git hooks of the respective git repos

  2. Steps

    1. Install gitlab with a 1.8 ruby as system ruby and 1.9.3 using rvm (or similar). Run gitlab with ruby 1.9.3
    2. Create an empty git repository
    3. Commit to repo, create branch
    4. Commit to new branch
    5. Push both branches to server
    6. Merge the two branches on gitlab
  3. Expected behaviour The two branches should be merged, also see issues: https://github.com/gitlabhq/gitlabhq/issues/3349, https://github.com/gitlabhq/gitlabhq/issues/3706, https://github.com/gitlabhq/gitlabhq/issues/3714

  4. Observed behaviour The git command is executed with the system ruby thus failing the gitlab-shell commit hook:

    remote: /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
    remote:     from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2
    remote:     from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/setup.rb:1:in `require'
    remote:     from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/setup.rb:1
    remote: error: hook declined to update refs/heads/master
    To /home/git/repositories/Spoerri/merge_request.git
    ! [remote rejected] master -> master (hook declined)
    error: failed to push some refs to '/home/git/repositories/Spoerri/merge_request.git'
  5. Output of checks Gitlab Check:

    git@svn:~/gitlab$ PATH="/usr/local/rvm/gems/ruby-1.9.3-p429@gitlab/bin:/usr/local/rvm/gems/ruby-1.9.3-p429/bin:/usr/local/rvm/gems/ruby-1.9.3-p429@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p429/bin:/usr/local/rvm/bin:/usr/bin:/bin" GEM_PATH="/usr/local/rvm/gems/ruby-1.9.3-p429@gitlab:/usr/local/rvm/gems/ruby-1.9.3-p429@global" bundle exec rake gitlab:check RAILS_ENV=production
    Checking Environment ...
    Git configured for git user? ... yes
    Has python2? ... yes
    python2 is supported version? ... yes
    Checking Environment ... Finished
    Checking GitLab Shell ...
    GitLab Shell version >= 1.4.0 ? ... OK (1.4.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
    post-receive hook up-to-date? ... yes
    post-receive hooks in repos are links: ...
    Pascal Spörri / merge_request ... ok
    Checking GitLab Shell ... Finished
    Checking Sidekiq ...
    Running? ... yes
    Checking Sidekiq ... Finished
    Checking GitLab ...
    Database config exists? ... yes
    Database is SQLite ... no
  6. Possible fixes I think it's sufficient to add the necessary environment variables to gitlab/lib/gitlab/satellite/merge_sction.rb . Since the merge command is executed by grit. Unfortunately the code below does not work:

      def merge!
        env = {:PATH => ENV[:PATH], :GEM_PATH => ENV[:GEM_PATH]}
        in_locked_and_timed_satellite do |merge_repo|
          if merge_in_satellite!(merge_repo)
            # push merge back to Gitolite
            # will raise CommandFailed when push fails
            merge_repo.git.push({raise: true, timeout: true, env: env}, :origin, merge_request.target_branch)
    
            # remove source branch
            if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch)
              # will raise CommandFailed when push fails
              merge_repo.git.push({raise: true, timeout: true, env: env}, :origin, ":#{merge_request.source_branch}")
            end
    
            # merge, push and branch removal successful
            true
          end
        end

    As far as I see gitlab executes the Grit::Git::native command which has an option to set environment variables. Which however remains unset as far as I can test. Setting system ruby to ruby 1.9.3-pWHATEVER is not a solution.

Assignee
Assign to
Time tracking