2018-09-05 05:50:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
require_relative 'test_env'
|
|
|
|
|
2017-01-04 13:43:06 -05:00
|
|
|
# This file is specific to specs in spec/lib/gitlab/git/
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
SEED_STORAGE_PATH = TestEnv.repos_path
|
2018-09-05 05:50:38 -04:00
|
|
|
TEST_REPO_PATH = 'gitlab-git-test.git'
|
|
|
|
TEST_NORMAL_REPO_PATH = 'not-bare-repo.git'
|
|
|
|
TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'
|
|
|
|
TEST_BROKEN_REPO_PATH = 'broken-repo.git'
|
|
|
|
TEST_GITATTRIBUTES_REPO_PATH = 'with-git-attributes.git'
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
module SeedHelper
|
2018-09-05 05:50:38 -04:00
|
|
|
GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__)
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
def ensure_seeds
|
2017-02-15 21:08:30 -05:00
|
|
|
if File.exist?(SEED_STORAGE_PATH)
|
|
|
|
FileUtils.rm_r(SEED_STORAGE_PATH)
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
FileUtils.mkdir_p(SEED_STORAGE_PATH)
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
create_bare_seeds
|
|
|
|
create_normal_seeds
|
|
|
|
create_mutable_seeds
|
|
|
|
create_broken_seeds
|
|
|
|
create_git_attributes
|
|
|
|
create_invalid_git_attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_bare_seeds
|
2017-03-14 13:30:53 -04:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{GITLAB_GIT_TEST_REPO_URL}),
|
2017-02-15 21:08:30 -05:00
|
|
|
chdir: SEED_STORAGE_PATH,
|
2017-01-04 13:43:06 -05:00
|
|
|
out: '/dev/null',
|
|
|
|
err: '/dev/null')
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_normal_seeds
|
2017-01-05 07:46:26 -05:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone #{TEST_REPO_PATH} #{TEST_NORMAL_REPO_PATH}),
|
2017-02-15 21:08:30 -05:00
|
|
|
chdir: SEED_STORAGE_PATH,
|
2017-01-04 13:43:06 -05:00
|
|
|
out: '/dev/null',
|
|
|
|
err: '/dev/null')
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_mutable_seeds
|
2017-08-28 03:31:41 -04:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_MUTABLE_REPO_PATH}),
|
2017-02-15 21:08:30 -05:00
|
|
|
chdir: SEED_STORAGE_PATH,
|
2017-01-04 13:43:06 -05:00
|
|
|
out: '/dev/null',
|
|
|
|
err: '/dev/null')
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
mutable_repo_full_path = File.join(SEED_STORAGE_PATH, TEST_MUTABLE_REPO_PATH)
|
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} branch -t feature origin/feature),
|
|
|
|
chdir: mutable_repo_full_path, out: '/dev/null', err: '/dev/null')
|
2017-01-04 13:43:06 -05:00
|
|
|
|
2017-03-14 13:30:53 -04:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} remote add expendable #{GITLAB_GIT_TEST_REPO_URL}),
|
2017-02-15 21:08:30 -05:00
|
|
|
chdir: mutable_repo_full_path, out: '/dev/null', err: '/dev/null')
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_broken_seeds
|
2017-01-05 07:46:26 -05:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_BROKEN_REPO_PATH}),
|
2017-02-15 21:08:30 -05:00
|
|
|
chdir: SEED_STORAGE_PATH,
|
2017-01-04 13:43:06 -05:00
|
|
|
out: '/dev/null',
|
|
|
|
err: '/dev/null')
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
refs_path = File.join(SEED_STORAGE_PATH, TEST_BROKEN_REPO_PATH, 'refs')
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
FileUtils.rm_r(refs_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_git_attributes
|
2018-09-05 05:50:38 -04:00
|
|
|
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_GITATTRIBUTES_REPO_PATH}),
|
|
|
|
chdir: SEED_STORAGE_PATH,
|
|
|
|
out: '/dev/null',
|
|
|
|
err: '/dev/null')
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
dir = File.join(SEED_STORAGE_PATH, 'with-git-attributes.git', 'info')
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
FileUtils.mkdir_p(dir)
|
|
|
|
|
|
|
|
File.open(File.join(dir, 'attributes'), 'w') do |handle|
|
|
|
|
handle.write <<-EOF.strip
|
|
|
|
# This is a comment, it should be ignored.
|
|
|
|
|
|
|
|
*.txt text
|
|
|
|
*.jpg -text
|
|
|
|
*.sh eol=lf gitlab-language=shell
|
|
|
|
*.haml.* gitlab-language=haml
|
|
|
|
foo/bar.* foo
|
|
|
|
*.cgi key=value?p1=v1&p2=v2
|
|
|
|
/*.png gitlab-language=png
|
|
|
|
*.binary binary
|
2018-09-05 05:50:38 -04:00
|
|
|
/custom-highlighting/*.gitlab-custom gitlab-language=ruby
|
|
|
|
/custom-highlighting/*.gitlab-cgi gitlab-language=erb?parent=json
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
# This uses a tab instead of spaces to ensure the parser also supports this.
|
|
|
|
*.md\tgitlab-language=markdown
|
|
|
|
bla/bla.txt
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_invalid_git_attributes
|
2017-02-15 21:08:30 -05:00
|
|
|
dir = File.join(SEED_STORAGE_PATH, 'with-invalid-git-attributes.git', 'info')
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
FileUtils.mkdir_p(dir)
|
|
|
|
|
|
|
|
enc = Encoding::UTF_16
|
|
|
|
|
|
|
|
File.open(File.join(dir, 'attributes'), 'w', encoding: enc) do |handle|
|
|
|
|
handle.write('# hello'.encode(enc))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|