summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-02-16 17:53:41 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-02-16 17:53:41 +0000
commitbb88412570e604c1960ea3dd3bfc686f539576dc (patch)
tree74c195e9eba8af74d2fb4ecd41ae95824c408320 /lib
parentf61186ba00ac1c6e96e4e16d7fe118debcdda1ea (diff)
parent6c12bf39b302cc8913f462ca0c3fd9579b354f26 (diff)
downloadgitlab-shell-bb88412570e604c1960ea3dd3bfc686f539576dc.tar.gz
Merge branch 'git-annex' into 'master'
Git annex support - [x] fix auth for git-annex - [x] enable git-annex for repository on first annex call - [x] config option to disable it - [x] write tests See merge request !55
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_config.rb4
-rw-r--r--lib/gitlab_shell.rb49
2 files changed, 47 insertions, 6 deletions
diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb
index c97743b..422898d 100644
--- a/lib/gitlab_config.rb
+++ b/lib/gitlab_config.rb
@@ -47,6 +47,10 @@ class GitlabConfig
@config['audit_usernames'] ||= false
end
+ def git_annex_enabled?
+ @config['git_annex_enabled'] ||= true
+ end
+
# Build redis command to write update event in gitlab queue
def redis_command
if redis.empty?
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 6422fff..ed25e07 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -22,6 +22,7 @@ class GitlabShell
ENV['GL_ID'] = @key_id
access = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
+
if access.allowed?
process_cmd
else
@@ -47,19 +48,45 @@ class GitlabShell
def parse_cmd
args = Shellwords.shellwords(@origin_cmd)
- raise DisallowedCommandError unless args.count == 2
- @git_cmd = args[0]
- @repo_name = escape_path(args[1])
+ @git_cmd = args.first
+
+ if @git_cmd == 'git-annex-shell' && @config.git_annex_enabled?
+ @repo_name = escape_path(args[2].gsub("\/~\/", ''))
+
+ # Make sure repository has git-annex enabled
+ init_git_annex(@repo_name)
+ else
+ raise DisallowedCommandError unless args.count == 2
+ @repo_name = escape_path(args.last)
+ end
end
def git_cmds
- %w(git-upload-pack git-receive-pack git-upload-archive)
+ %w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell)
end
def process_cmd
repo_full_path = File.join(repos_path, repo_name)
- $logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}."
- exec_cmd(@git_cmd, repo_full_path)
+
+ if @git_cmd == 'git-annex-shell' && @config.git_annex_enabled?
+ args = Shellwords.shellwords(@origin_cmd)
+ parsed_args =
+ args.map do |arg|
+ # Convert /~/group/project.git to group/project.git
+ # to make git annex path compatible with gitlab-shell
+ if arg =~ /\A\/~\/.*\.git\Z/
+ repo_full_path
+ else
+ arg
+ end
+ end
+
+ $logger.info "gitlab-shell: executing git-annex command <#{parsed_args.join(' ')}> for #{log_username}."
+ exec_cmd(*parsed_args)
+ else
+ $logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}."
+ exec_cmd(@git_cmd, repo_full_path)
+ end
end
# This method is not covered by Rspec because it ends the current Ruby process.
@@ -99,4 +126,14 @@ class GitlabShell
abort "Wrong repository path"
end
end
+
+ def init_git_annex(path)
+ full_repo_path = File.join(repos_path, path)
+
+ unless File.exists?(File.join(full_repo_path, '.git', 'annex'))
+ cmd = %W(git --git-dir=#{full_repo_path} annex init "GitLab")
+ system(*cmd)
+ $logger.info "Enable git-annex for repository: #{path}."
+ end
+ end
end