diff options
Diffstat (limited to 'lib/gitlab/shell.rb')
-rw-r--r-- | lib/gitlab/shell.rb | 100 |
1 files changed, 23 insertions, 77 deletions
diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index e7158148b59..6053ad8d08e 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -6,8 +6,6 @@ require 'securerandom' module Gitlab class Shell - GITLAB_SHELL_ENV_VARS = %w(GIT_TERMINAL_PROMPT).freeze - Error = Class.new(StandardError) class << self @@ -36,8 +34,31 @@ module Gitlab .join('GITLAB_SHELL_VERSION')).strip end + # Return GitLab shell version + # + # @return [String] version + def version + @version ||= File.read(gitlab_shell_version_file).chomp if File.readable?(gitlab_shell_version_file) + end + + # Return a SSH url for a given project path + # + # @param [String] full_path project path (URL) + # @return [String] SSH URL + def url_to_repo(full_path) + Gitlab.config.gitlab_shell.ssh_path_prefix + "#{full_path}.git" + end + private + def gitlab_shell_path + File.expand_path(Gitlab.config.gitlab_shell.path) + end + + def gitlab_shell_version_file + File.join(gitlab_shell_path, 'VERSION') + end + # Create (if necessary) and link the secret token file def generate_and_link_secret_token secret_file = Gitlab.config.gitlab_shell.secret_file @@ -56,47 +77,6 @@ module Gitlab end end - # Initialize a new project repository using a Project model - # - # @param [Project] project - # @return [Boolean] whether repository could be created - def create_project_repository(project) - create_repository(project.repository_storage, project.disk_path, project.full_path) - end - - # Initialize a new wiki repository using a Project model - # - # @param [Project] project - # @return [Boolean] whether repository could be created - def create_wiki_repository(project) - create_repository(project.repository_storage, project.wiki.disk_path, project.wiki.full_path) - end - - # Init new repository - # - # @example Create a repository - # create_repository("default", "path/to/gitlab-ci", "gitlab/gitlab-ci") - # - # @param [String] storage the shard key - # @param [String] disk_path project path on disk - # @param [String] gl_project_path project name - # @return [Boolean] whether repository could be created - def create_repository(storage, disk_path, gl_project_path) - relative_path = disk_path.dup - relative_path << '.git' unless relative_path.end_with?('.git') - - # During creation of a repository, gl_repository may not be known - # because that depends on a yet-to-be assigned project ID in the - # database (e.g. project-1234), so for now it is blank. - repository = Gitlab::Git::Repository.new(storage, relative_path, '', gl_project_path) - wrapped_gitaly_errors { repository.gitaly_repository_client.create_repository } - - true - rescue => err # Once the Rugged codes gets removes this can be improved - Rails.logger.error("Failed to add repository #{storage}/#{disk_path}: #{err}") # rubocop:disable Gitlab/RailsLogger - false - end - # Import wiki repository from external service # # @param [Project] project @@ -238,25 +218,6 @@ module Gitlab false end - # Return a SSH url for a given project path - # - # @param [String] full_path project path (URL) - # @return [String] SSH URL - def url_to_repo(full_path) - Gitlab.config.gitlab_shell.ssh_path_prefix + "#{full_path}.git" - end - - # Return GitLab shell version - # - # @return [String] version - def version - gitlab_shell_version_file = "#{gitlab_shell_path}/VERSION" - - if File.readable?(gitlab_shell_version_file) - File.read(gitlab_shell_version_file).chomp - end - end - # Check if repository exists on disk # # @example Check if repository exists @@ -271,23 +232,8 @@ module Gitlab false end - # Return hooks folder path used by projects - # - # @return [String] path - def hooks_path - File.join(gitlab_shell_path, 'hooks') - end - protected - def gitlab_shell_path - File.expand_path(Gitlab.config.gitlab_shell.path) - end - - def gitlab_shell_user_home - File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") - end - def full_path(storage, dir_name) raise ArgumentError.new("Directory name can't be blank") if dir_name.blank? |