Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-04-13 08:27:45 +0300
committerStan Hu <stanhu@gmail.com>2015-04-28 06:42:38 +0300
commit72a7febeada2c58c98caee8bb7ce18886a7c0868 (patch)
tree22cde467a3b87e93babb526b154003ffad12fef6 /spec/support/test_env.rb
parent9f443f42578f8f995415f3d0b9aa9ee8aebeff0b (diff)
Fix "Revspec not found" errors when viewing diffs in a forked project with submodules
Closes #1413
Diffstat (limited to 'spec/support/test_env.rb')
-rw-r--r--spec/support/test_env.rb53
1 files changed, 46 insertions, 7 deletions
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index 44d70e741b2..d1844bd2b87 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -14,6 +14,10 @@ module TestEnv
'master' => '5937ac0'
}
+ FORKED_BRANCH_SHA = BRANCH_SHA.merge({
+ 'add-submodule-version-bump' => '3f547c08'
+ })
+
# Test environment
#
# See gitlab.yml.example test section for paths
@@ -31,6 +35,8 @@ module TestEnv
# Create repository for FactoryGirl.create(:project)
setup_factory_repo
+ # Create repository for FactoryGirl.create(:forked_project_with_submodules)
+ setup_forked_repo
end
def disable_mailer
@@ -61,14 +67,26 @@ module TestEnv
end
def setup_factory_repo
- clone_url = "https://gitlab.com/gitlab-org/#{factory_repo_name}.git"
+ setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name,
+ BRANCH_SHA)
+ end
+
+ # This repo has a submodule commit that is not present in the main test
+ # repository.
+ def setup_forked_repo
+ setup_repo(forked_repo_path, forked_repo_path_bare, forked_repo_name,
+ FORKED_BRANCH_SHA)
+ end
+
+ def setup_repo(repo_path, repo_path_bare, repo_name, branch_sha)
+ clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git"
- unless File.directory?(factory_repo_path)
- system(*%W(git clone -q #{clone_url} #{factory_repo_path}))
+ unless File.directory?(repo_path)
+ system(*%W(git clone -q #{clone_url} #{repo_path}))
end
- Dir.chdir(factory_repo_path) do
- BRANCH_SHA.each do |branch, sha|
+ Dir.chdir(repo_path) do
+ branch_sha.each do |branch, sha|
# Try to reset without fetching to avoid using the network.
reset = %W(git update-ref refs/heads/#{branch} #{sha})
unless system(*reset)
@@ -85,7 +103,7 @@ module TestEnv
end
# We must copy bare repositories because we will push to them.
- system(git_env, *%W(git clone -q --bare #{factory_repo_path} #{factory_repo_path_bare}))
+ system(git_env, *%W(git clone -q --bare #{repo_path} #{repo_path_bare}))
end
def copy_repo(project)
@@ -100,6 +118,14 @@ module TestEnv
Gitlab.config.gitlab_shell.repos_path
end
+ def copy_forked_repo_with_submodules(project)
+ base_repo_path = File.expand_path(forked_repo_path_bare)
+ target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")
+ FileUtils.mkdir_p(target_repo_path)
+ FileUtils.cp_r("#{base_repo_path}/.", target_repo_path)
+ FileUtils.chmod_R 0755, target_repo_path
+ end
+
private
def factory_repo_path
@@ -114,9 +140,22 @@ module TestEnv
'gitlab-test'
end
+ def forked_repo_path
+ @forked_repo_path ||= Rails.root.join('tmp', 'tests', forked_repo_name)
+ end
+
+ def forked_repo_path_bare
+ "#{forked_repo_path}_bare"
+ end
+
+ def forked_repo_name
+ 'gitlab-test-fork'
+ end
+
+
# Prevent developer git configurations from being persisted to test
# repositories
def git_env
- {'GIT_TEMPLATE_DIR' => ''}
+ { 'GIT_TEMPLATE_DIR' => '' }
end
end