Commit 57933b9f authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Validate worktree paths

parent 407ef708
...@@ -19,6 +19,8 @@ module Gitlab ...@@ -19,6 +19,8 @@ module Gitlab
].freeze ].freeze
SEARCH_CONTEXT_LINES = 3 SEARCH_CONTEXT_LINES = 3
GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze
REBASE_WORKTREE_PREFIX = 'rebase'.freeze
SQUASH_WORKTREE_PREFIX = 'squash'.freeze
NoRepository = Class.new(StandardError) NoRepository = Class.new(StandardError)
InvalidBlobName = Class.new(StandardError) InvalidBlobName = Class.new(StandardError)
...@@ -1213,7 +1215,7 @@ module Gitlab ...@@ -1213,7 +1215,7 @@ module Gitlab
end end
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:) def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
rebase_path = rebase_dir_path(rebase_id) rebase_path = worktree_path(REBASE_WORKTREE_PREFIX, rebase_id)
env = git_env_for_user(user) env = git_env_for_user(user)
with_worktree(rebase_path, branch, env: env) do with_worktree(rebase_path, branch, env: env) do
...@@ -1232,11 +1234,11 @@ module Gitlab ...@@ -1232,11 +1234,11 @@ module Gitlab
end end
def rebase_in_progress?(rebase_id) def rebase_in_progress?(rebase_id)
fresh_worktree?(rebase_dir_path(rebase_id)) fresh_worktree?(worktree_path(REBASE_WORKTREE_PREFIX, rebase_id))
end end
def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:) def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:)
squash_path = squash_dir_path(squash_id) squash_path = worktree_path(SQUASH_WORKTREE_PREFIX, squash_id)
env = git_env_for_user(user).merge( env = git_env_for_user(user).merge(
'GIT_AUTHOR_NAME' => author.name, 'GIT_AUTHOR_NAME' => author.name,
'GIT_AUTHOR_EMAIL' => author.email 'GIT_AUTHOR_EMAIL' => author.email
...@@ -1267,7 +1269,7 @@ module Gitlab ...@@ -1267,7 +1269,7 @@ module Gitlab
end end
def squash_in_progress?(squash_id) def squash_in_progress?(squash_id)
fresh_worktree?(squash_dir_path(squash_id)) fresh_worktree?(worktree_path(SQUASH_WORKTREE_PREFIX, squash_id))
end end
def gitaly_repository def gitaly_repository
...@@ -1368,12 +1370,12 @@ module Gitlab ...@@ -1368,12 +1370,12 @@ module Gitlab
end end
end end
def rebase_dir_path(id) def worktree_path(prefix, id)
File.join(path, 'gitlab-worktree', "rebase-#{id}") id = id.to_s
end raise ArgumentError, "worktree id can't be empty" unless id.present?
raise ArgumentError, "worktree id can't contain slashes " if id.include?("/")
def squash_dir_path(id) File.join(path, 'gitlab-worktree', "#{prefix}-#{id}")
File.join(path, 'gitlab-worktree', "squash-#{id}")
end end
def git_env_for_user(user) def git_env_for_user(user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment