summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-03 21:05:45 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-03 21:05:45 +0200
commitb83ab386abc1b1591e7f9afa3d5d5b6cc1f5ae50 (patch)
tree8253c45abdd6370dc9c4a75502417e156260192e
parente620575dcdfa3214229d5e660016e6410117729f (diff)
downloadgitlab-shell-b83ab386abc1b1591e7f9afa3d5d5b6cc1f5ae50.tar.gz
gitlab-shell base implementation
-rw-r--r--.gitignore1
-rw-r--r--config.yml.example2
-rw-r--r--lib/gitlab_shell.rb17
3 files changed, 18 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1d3ed4c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config.yml
diff --git a/config.yml.example b/config.yml.example
new file mode 100644
index 0000000..1bf9834
--- /dev/null
+++ b/config.yml.example
@@ -0,0 +1,2 @@
+user: git
+repos_path: "/home/git/repositories"
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 4d4d240..93acc57 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -1,17 +1,25 @@
require 'open3'
+require 'yaml'
+
class GitlabShell
- attr_accessor :username, :repo_name, :git_cmd
+ attr_accessor :username, :repo_name, :git_cmd, :repos_path
def initialize
@username = ARGV.shift
@origin_cmd = ENV['SSH_ORIGINAL_COMMAND']
+ @config = YAML.load_file(File.join(ROOT_PATH, 'config.yml'))
+ @repos_path = @config['repos_path']
end
def exec
if @origin_cmd
parse_cmd
- return system("git-upload-pack /home/gip/repositories/#{@repo_name}")
+ if git_cmds.include?(@git_cmd)
+ process_cmd
+ else
+ puts 'Not allowed command'
+ end
else
puts "Welcome #{@username}!"
end
@@ -28,4 +36,9 @@ class GitlabShell
def git_cmds
%w(git-upload-pack git-receive-pack git-upload-archive)
end
+
+ def process_cmd
+ repo_full_path = File.join(repos_path, repo_name)
+ system("#{@git_cmd} #{repo_full_path}")
+ end
end