summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-03 20:43:25 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-03 20:43:25 +0200
commite620575dcdfa3214229d5e660016e6410117729f (patch)
tree7feb657b070e2290240eb32ada29ede3d3f74d35
parentbb9863e87055daf8347de65847c4a0a82ab0dfa8 (diff)
downloadgitlab-shell-e620575dcdfa3214229d5e660016e6410117729f.tar.gz
working git upload
-rwxr-xr-xbin/gitlab-shell11
-rw-r--r--lib/gitlab_shell.rb31
2 files changed, 38 insertions, 4 deletions
diff --git a/bin/gitlab-shell b/bin/gitlab-shell
index e8799bb..0c3b654 100755
--- a/bin/gitlab-shell
+++ b/bin/gitlab-shell
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby
+unless ENV['SSH_CONNECTION']
+ puts "Only ssh allowed"
+ exit
+end
#
# GitLab shell, invoked from ~/.ssh/authorized_keys
#
-
-ROOT_PATH = File.expand_path('..', __FILE__)
-
-puts ENV['SSH_CONNECTION'].inspect
+ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "..")
+require File.join(ROOT_PATH, 'lib', 'gitlab_shell')
+GitlabShell.new.exec
exit
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
new file mode 100644
index 0000000..4d4d240
--- /dev/null
+++ b/lib/gitlab_shell.rb
@@ -0,0 +1,31 @@
+require 'open3'
+class GitlabShell
+ attr_accessor :username, :repo_name, :git_cmd
+
+ def initialize
+ @username = ARGV.shift
+ @origin_cmd = ENV['SSH_ORIGINAL_COMMAND']
+ end
+
+ def exec
+ if @origin_cmd
+ parse_cmd
+
+ return system("git-upload-pack /home/gip/repositories/#{@repo_name}")
+ else
+ puts "Welcome #{@username}!"
+ end
+ end
+
+ protected
+
+ def parse_cmd
+ args = @origin_cmd.split(' ')
+ @git_cmd = args.shift
+ @repo_name = args.shift
+ end
+
+ def git_cmds
+ %w(git-upload-pack git-receive-pack git-upload-archive)
+ end
+end