summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-31 06:23:32 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-31 06:23:32 -0700
commitdb79c32e62c9db69e63154d0abced6b8bac56c3d (patch)
tree5620ce96dbc43ed2a6b04207a8fb01a25c29b83b
parentbe2f82b0af3c9aea1bac1e27217acbf77b4c88aa (diff)
parentd64ddc87558bc36d41593772e8399df05b89d5bf (diff)
downloadgitlab-shell-db79c32e62c9db69e63154d0abced6b8bac56c3d.tar.gz
Merge pull request #87 from bobot/master
Execute command directly without using shell
-rw-r--r--lib/gitlab_shell.rb16
-rw-r--r--spec/gitlab_shell_spec.rb4
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 01ef4a1..67ffb26 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -1,4 +1,5 @@
require 'open3'
+require 'shellwords'
require_relative 'gitlab_net'
@@ -40,9 +41,9 @@ class GitlabShell
protected
def parse_cmd
- args = @origin_cmd.split(' ')
- @git_cmd = args.shift
- @repo_name = args.shift
+ args = Shellwords.shellwords(@origin_cmd)
+ @git_cmd = args[0]
+ @repo_name = args[1]
end
def git_cmds
@@ -51,17 +52,16 @@ class GitlabShell
def process_cmd
repo_full_path = File.join(repos_path, repo_name)
- cmd = "#{@git_cmd} #{repo_full_path}"
- $logger.info "gitlab-shell: executing git command <#{cmd}> for #{log_username}."
- exec_cmd(cmd)
+ $logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}."
+ exec_cmd(@git_cmd,repo_full_path)
end
def validate_access
api.allowed?(@git_cmd, @repo_name, @key_id, '_any')
end
- def exec_cmd args
- Kernel::exec args
+ def exec_cmd *args
+ Kernel::exec *args
end
def api
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 44dca6d..3243dd3 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -60,7 +60,7 @@ describe GitlabShell do
end
it "should execute the command" do
- subject.should_receive(:exec_cmd).with("git-upload-pack #{File.join(repository_path, 'gitlab-ci.git')}")
+ subject.should_receive(:exec_cmd).with("git-upload-pack", File.join(repository_path, 'gitlab-ci.git'))
end
it "should set the GL_ID environment variable" do
@@ -89,7 +89,7 @@ describe GitlabShell do
end
it "should execute the command" do
- subject.should_receive(:exec_cmd).with("git-receive-pack #{File.join(repository_path, 'gitlab-ci.git')}")
+ subject.should_receive(:exec_cmd).with("git-receive-pack", File.join(repository_path, 'gitlab-ci.git'))
end
it "should log the command execution" do