Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9351f7a5
Commit
9351f7a5
authored
Mar 30, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-03-30
parents
c599b642
80b475d5
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
240 additions
and
234 deletions
+240
-234
Gemfile.lock
Gemfile.lock
+1
-1
app/models/ci/artifact_blob.rb
app/models/ci/artifact_blob.rb
+3
-4
app/models/project.rb
app/models/project.rb
+9
-10
app/views/shared/milestones/_top.html.haml
app/views/shared/milestones/_top.html.haml
+3
-2
changelogs/unreleased/ac-pages-port.yml
changelogs/unreleased/ac-pages-port.yml
+5
-0
changelogs/unreleased/add-milestone-path-to-dashboard-milestones-breadcrumb-link.yml
...ilestone-path-to-dashboard-milestones-breadcrumb-link.yml
+5
-0
doc/user/gitlab_com/index.md
doc/user/gitlab_com/index.md
+9
-1
doc/user/project/repository/index.md
doc/user/project/repository/index.md
+3
-2
lib/api/helpers/internal_helpers.rb
lib/api/helpers/internal_helpers.rb
+0
-12
lib/api/internal.rb
lib/api/internal.rb
+1
-2
lib/gitlab/ee_compat_check.rb
lib/gitlab/ee_compat_check.rb
+91
-57
lib/gitlab/git/hook_env.rb
lib/gitlab/git/hook_env.rb
+12
-14
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+2
-12
lib/gitlab/gitaly_client/util.rb
lib/gitlab/gitaly_client/util.rb
+3
-5
spec/lib/gitlab/git/hook_env_spec.rb
spec/lib/gitlab/git/hook_env_spec.rb
+28
-43
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+2
-18
spec/lib/gitlab/git/rev_list_spec.rb
spec/lib/gitlab/git/rev_list_spec.rb
+1
-12
spec/lib/gitlab/gitaly_client/util_spec.rb
spec/lib/gitlab/gitaly_client/util_spec.rb
+7
-4
spec/models/ci/artifact_blob_spec.rb
spec/models/ci/artifact_blob_spec.rb
+13
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+28
-0
spec/requests/api/internal_spec.rb
spec/requests/api/internal_spec.rb
+14
-35
No files found.
Gemfile.lock
View file @
9351f7a5
...
...
@@ -128,7 +128,7 @@ GEM
activesupport (>= 4.0.0)
mime-types (>= 1.16)
cause (0.1)
charlock_holmes (0.7.
5
)
charlock_holmes (0.7.
6
)
childprocess (0.7.0)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
...
...
app/models/ci/artifact_blob.rb
View file @
9351f7a5
...
...
@@ -36,16 +36,15 @@ module Ci
def
external_url
(
project
,
job
)
return
unless
external_link?
(
job
)
full_path_parts
=
project
.
full_path_components
top_level_group
=
full_path_parts
.
shift
url_project_path
=
project
.
full_path
.
partition
(
'/'
).
last
artifact_path
=
[
'-'
,
*
full_path_parts
,
'-'
,
'-'
,
url_project_path
,
'-'
,
'jobs'
,
job
.
id
,
'artifacts'
,
path
].
join
(
'/'
)
"
#{
p
ages_config
.
protocol
}
://
#{
top_level_group
}
.
#{
pages_config
.
host
}
/
#{
artifact_path
}
"
"
#{
p
roject
.
pages_group_url
}
/
#{
artifact_path
}
"
end
def
external_link?
(
job
)
...
...
app/models/project.rb
View file @
9351f7a5
...
...
@@ -1360,20 +1360,19 @@ class Project < ActiveRecord::Base
Dir
.
exist?
(
public_pages_path
)
end
def
pages_url
subdomain
,
_
,
url_path
=
full_path
.
partition
(
'/'
)
# The hostname always needs to be in downcased
# All web servers convert hostname to lowercase
host
=
"
#{
subdomain
}
.
#{
Settings
.
pages
.
host
}
"
.
downcase
def
pages_group_url
# The host in URL always needs to be downcased
url
=
Gitlab
.
config
.
pages
.
url
.
sub
(
%r{^https?://}
)
do
|
prefix
|
"
#{
prefix
}#{
subdomain
}
."
Gitlab
.
config
.
pages
.
url
.
sub
(
%r{^https?://}
)
do
|
prefix
|
"
#{
prefix
}#{
pages_
subdomain
}
."
end
.
downcase
end
def
pages_url
url
=
pages_group_url
url_path
=
full_path
.
partition
(
'/'
).
last
# If the project path is the same as host, we serve it as group page
return
url
if
host
==
url_path
return
url
if
url
==
"
#{
Settings
.
pages
.
protocol
}
://
#{
url_path
}
"
"
#{
url
}
/
#{
url_path
}
"
end
...
...
app/views/shared/milestones/_top.html.haml
View file @
9351f7a5
-
page_title
milestone
.
title
,
"Milestones"
-
page_title
@milestone
.
title
-
@breadcrumb_link
=
dashboard_milestone_path
(
milestone
.
safe_title
,
title:
milestone
.
title
)
-
group
=
local_assigns
[
:group
]
...
...
@@ -17,7 +18,7 @@
Milestone
#{
milestone
.
title
}
-
if
milestone
.
due_date
||
milestone
.
start_date
%span
.creator
·
&
nbsp;&
middot;
=
milestone_date_range
(
milestone
)
-
if
group
.pull-right
...
...
changelogs/unreleased/ac-pages-port.yml
0 → 100644
View file @
9351f7a5
---
title
:
Add missing port to artifact links
merge_request
:
author
:
type
:
fixed
changelogs/unreleased/add-milestone-path-to-dashboard-milestones-breadcrumb-link.yml
0 → 100644
View file @
9351f7a5
---
title
:
Update dashboard milestones breadcrumb link
merge_request
:
17933
author
:
George Tsiolis
type
:
fixed
doc/user/gitlab_com/index.md
View file @
9351f7a5
...
...
@@ -51,7 +51,7 @@ Below are the settings for [GitLab Pages].
| TLS certificates support| yes | no |
The maximum size of your Pages site is regulated by the artifacts maximum size
which is part of
[
GitLab CI
](
#gitlab-ci
)
.
which is part of
[
GitLab CI
/CD
](
#gitlab-ci-cd
)
.
## GitLab CI/CD
...
...
@@ -61,6 +61,14 @@ Below are the current settings regarding [GitLab CI/CD](../../ci/README.md).
| ----------- | ----------------- | ------------- |
| Artifacts maximum size | 1G | 100M |
## Repository size limit
The maximum size your Git repository is allowed to be including LFS.
| Setting | GitLab.com | Default |
| ----------- | ----------------- | ------------- |
| Repository size including LFS | 10G | Unlimited |
## Shared Runners
Shared Runners on GitLab.com run in [autoscale mode] and powered by
...
...
doc/user/project/repository/index.md
View file @
9351f7a5
...
...
@@ -132,8 +132,9 @@ Use GPG to [sign your commits](gpg_signed_commits/index.md).
## Repository size
In GitLab.com, your repository size limit it 10GB. For other instances,
the repository size is limited by your system administrators.
On GitLab.com, your
[
repository size limit is 10GB
](
../../gitlab_com/index.md#repository-size-limit
)
(including LFS). For other instances, the repository size is limited by your
system administrators.
You can also
[
reduce a repository size using Git
](
reducing_the_repo_size_using_git.md
)
.
...
...
lib/api/helpers/internal_helpers.rb
View file @
9351f7a5
...
...
@@ -29,18 +29,6 @@ module API
{}
end
def
fix_git_env_repository_paths
(
env
,
repository_path
)
if
obj_dir_relative
=
env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
presence
env
[
'GIT_OBJECT_DIRECTORY'
]
=
File
.
join
(
repository_path
,
obj_dir_relative
)
end
if
alt_obj_dirs_relative
=
env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
].
presence
env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
]
=
alt_obj_dirs_relative
.
map
{
|
dir
|
File
.
join
(
repository_path
,
dir
)
}
end
env
end
def
log_user_activity
(
actor
)
commands
=
Gitlab
::
GitAccess
::
DOWNLOAD_COMMANDS
...
...
lib/api/internal.rb
View file @
9351f7a5
...
...
@@ -21,8 +21,7 @@ module API
# Stores some Git-specific env thread-safely
env
=
parse_env
env
=
fix_git_env_repository_paths
(
env
,
repository_path
)
if
project
Gitlab
::
Git
::
Env
.
set
(
env
)
Gitlab
::
Git
::
HookEnv
.
set
(
gl_repository
,
env
)
if
project
actor
=
if
params
[
:key_id
]
...
...
lib/gitlab/ee_compat_check.rb
View file @
9351f7a5
...
...
@@ -2,8 +2,8 @@
module
Gitlab
# Checks if a set of migrations requires downtime or not.
class
EeCompatCheck
DEFAULT
_CE_PROJECT_URL
=
'https://gitlab.com/gitlab-org/gitlab-ce'
.
freeze
EE_REPO_URL
=
'https://gitlab.com/gitlab-org/gitlab-ee.git'
.
freeze
CANONICAL
_CE_PROJECT_URL
=
'https://gitlab.com/gitlab-org/gitlab-ce'
.
freeze
CANONICAL_
EE_REPO_URL
=
'https://gitlab.com/gitlab-org/gitlab-ee.git'
.
freeze
CHECK_DIR
=
Rails
.
root
.
join
(
'ee_compat_check'
)
IGNORED_FILES_REGEX
=
%r{VERSION|CHANGELOG
\.
md|db/schema
\.
rb}i
.
freeze
PLEASE_READ_THIS_BANNER
=
%Q{
...
...
@@ -11,57 +11,81 @@ module Gitlab
===================== PLEASE READ THIS =====================
============================================================
}
.
freeze
STAY_STRONG_LINK_TO_DOCS
=
%Q{
Stay 💪! For more information, see
https://docs.gitlab.com/ce/development/automatic_ce_ee_merge.html
}
.
freeze
THANKS_FOR_READING_BANNER
=
%Q{
============================================================
==================== THANKS FOR READING ====================
============================================================
\n
}
.
freeze
attr_reader
:ee_repo_dir
,
:patches_dir
,
:ce_project_url
,
:ce_repo_url
,
:ce_branch
,
:ee_branch_found
attr_reader
:ee_repo_dir
,
:patches_dir
attr_reader
:ce_project_url
,
:ee_repo_url
attr_reader
:ce_branch
,
:ee_remote_with_branch
,
:ee_branch_found
attr_reader
:job_id
,
:failed_files
def
initialize
(
branch
:,
ce_project_url:
DEFAULT
_CE_PROJECT_URL
,
job_id:
nil
)
def
initialize
(
branch
:,
ce_project_url:
CANONICAL
_CE_PROJECT_URL
,
job_id:
nil
)
@ee_repo_dir
=
CHECK_DIR
.
join
(
'ee-repo'
)
@patches_dir
=
CHECK_DIR
.
join
(
'patches'
)
@ce_branch
=
branch
@ce_project_url
=
ce_project_url
@
ce_repo_url
=
"
#{
ce_project_url
}
.git"
@
ee_repo_url
=
ce_public_repo_url
.
sub
(
'gitlab-ce'
,
'gitlab-ee'
)
@job_id
=
job_id
end
def
check
ensure_patches_dir
add_remote
(
'canonical-ce'
,
"
#{
DEFAULT_CE_PROJECT_URL
}
.git"
)
generate_patch
(
branch:
ce_branch
,
patch_path:
ce_patch_full_path
,
remote:
'canonical-ce'
)
# We're generating the patch against the canonical-ce remote since forks'
# master branch are not necessarily up-to-date.
add_remote
(
'canonical-ce'
,
"
#{
CANONICAL_CE_PROJECT_URL
}
.git"
)
generate_patch
(
branch:
ce_branch
,
patch_path:
ce_patch_full_path
,
branch_remote:
'origin'
,
master_remote:
'canonical-ce'
)
ensure_ee_repo
Dir
.
chdir
(
ee_repo_dir
)
do
step
(
"In the
#{
ee_repo_dir
}
directory"
)
add_remote
(
'canonical-ee'
,
EE_REPO_URL
)
ee_remotes
.
each
do
|
key
,
url
|
add_remote
(
key
,
url
)
end
fetch
(
branch:
'master'
,
depth:
20
,
remote:
'canonical-ee'
)
status
=
catch
(
:halt_check
)
do
ce_branch_compat_check!
delete_ee_branches_locally!
ee_branch_presence_check!
step
(
"Checking out
#{
ee_
branch_found
}
"
,
%W[git checkout -b
#{
ee_branch_found
}
canonical-ee
/
#{
ee_branch_found
}
]
)
generate_patch
(
branch:
ee_branch_found
,
patch_path:
ee_patch_full_path
,
remote:
'canonical-ee'
)
step
(
"Checking out
#{
ee_
remote_with_branch
}
/
#{
ee_branch_found
}
"
,
%W[git checkout -b
#{
ee_branch_found
}
#{
ee_remote_with_branch
}
/
#{
ee_branch_found
}
]
)
generate_patch
(
branch:
ee_branch_found
,
patch_path:
ee_patch_full_path
,
branch_remote:
ee_remote_with_branch
,
master_
remote:
'canonical-ee'
)
ee_branch_compat_check!
end
delete_ee_branches_locally!
if
status
.
nil?
true
else
false
end
status
.
nil?
end
end
private
def
fork?
ce_project_url
!=
CANONICAL_CE_PROJECT_URL
end
def
ee_remotes
return
@ee_remotes
if
defined?
(
@ee_remotes
)
remotes
=
{
'ee'
=>
ee_repo_url
,
'canonical-ee'
=>
CANONICAL_EE_REPO_URL
}
remotes
.
delete
(
'ee'
)
unless
fork
?
@ee_remotes
=
remotes
end
def
add_remote
(
name
,
url
)
step
(
"Adding the
#{
name
}
remote (
#{
url
}
)"
,
...
...
@@ -70,28 +94,32 @@ module Gitlab
end
def
ensure_ee_repo
if
Dir
.
exist?
(
ee_repo_dir
)
step
(
"
#{
ee_repo_dir
}
already exists"
)
else
step
(
"Cloning
#{
EE_REPO_URL
}
into
#{
ee_repo_dir
}
"
,
%W[git clone --branch master --single-branch --depth=200
#{
EE_REPO_URL
}
#{
ee_repo_dir
}
]
)
unless
clone_repo
(
ee_repo_url
,
ee_repo_dir
)
# Fallback to using the canonical EE if there is no forked EE
clone_repo
(
CANONICAL_EE_REPO_URL
,
ee_repo_dir
)
end
end
def
clone_repo
(
url
,
dir
)
_
,
status
=
step
(
"Cloning
#{
url
}
into
#{
dir
}
"
,
%W[git clone --branch master --single-branch --depth=200
#{
url
}
#{
dir
}
]
)
status
.
zero?
end
def
ensure_patches_dir
FileUtils
.
mkdir_p
(
patches_dir
)
end
def
generate_patch
(
branch
:,
patch_path
:,
remote
:)
def
generate_patch
(
branch
:,
patch_path
:,
branch_remote
:,
master_
remote
:)
FileUtils
.
rm
(
patch_path
,
force:
true
)
find_merge_base_with_master
(
branch:
branch
,
master_remote:
remote
)
find_merge_base_with_master
(
branch:
branch
,
branch_remote:
branch_remote
,
master_remote:
master_
remote
)
step
(
"Generating the patch against
#{
remote
}
/master in
#{
patch_path
}
"
,
%W[git diff --binary
#{
remote
}
/master...origin
/
#{
branch
}
]
"Generating the patch against
#{
master_
remote
}
/master in
#{
patch_path
}
"
,
%W[git diff --binary
#{
master_remote
}
/master...
#{
branch_remote
}
/
#{
branch
}
]
)
do
|
output
,
status
|
throw
(
:halt_check
,
:ko
)
unless
status
.
zero?
...
...
@@ -109,23 +137,22 @@ module Gitlab
end
def
ee_branch_presence_check!
_
,
status
=
step
(
"Fetching origin/
#{
ee_branch_prefix
}
"
,
%W[git fetch canonical-ee
#{
ee_branch_prefix
}
]
)
if
status
.
zero?
@ee_branch_found
=
ee_branch_prefix
return
ee_remotes
.
keys
.
each
do
|
remote
|
[
ee_branch_prefix
,
ee_branch_suffix
].
each
do
|
branch
|
_
,
status
=
step
(
"Fetching
#{
remote
}
/
#{
ee_branch_prefix
}
"
,
%W[git fetch
#{
remote
}
#{
branch
}
]
)
if
status
.
zero?
@ee_remote_with_branch
=
remote
@ee_branch_found
=
branch
return
true
end
end
end
_
,
status
=
step
(
"Fetching origin/
#{
ee_branch_suffix
}
"
,
%W[git fetch canonical-ee
#{
ee_branch_suffix
}
]
)
if
status
.
zero?
@ee_branch_found
=
ee_branch_suffix
else
puts
puts
ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg
puts
puts
ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg
throw
(
:halt_check
,
:ko
)
end
throw
(
:halt_check
,
:ko
)
end
def
ee_branch_compat_check!
...
...
@@ -181,10 +208,10 @@ module Gitlab
command
(
%W[git branch --delete --force
#{
ee_branch_suffix
}
]
)
end
def
merge_base_found?
(
master_remote
:,
branch
:)
def
merge_base_found?
(
branch
:,
branch_remote
:,
master_remote
:)
step
(
"Finding merge base with
#{
master_remote
}
/master"
,
%W[git merge-base
#{
master_remote
}
/master
origin
/
#{
branch
}
]
%W[git merge-base
#{
master_remote
}
/master
#{
branch_remote
}
/
#{
branch
}
]
)
do
|
output
,
status
|
if
status
.
zero?
puts
"Merge base was found:
#{
output
}
"
...
...
@@ -193,7 +220,7 @@ module Gitlab
end
end
def
find_merge_base_with_master
(
branch
:,
master_remote
:)
def
find_merge_base_with_master
(
branch
:,
branch_remote
:,
master_remote
:)
# Start with (Math.exp(3).to_i = 20) until (Math.exp(6).to_i = 403)
# In total we go (20 + 54 + 148 + 403 = 625) commits deeper
depth
=
20
...
...
@@ -202,10 +229,10 @@ module Gitlab
depth
+=
Math
.
exp
(
factor
).
to_i
# Repository is initially cloned with a depth of 20 so we need to fetch
# deeper in the case the branch has more than 20 commits on top of master
fetch
(
branch:
branch
,
depth:
depth
,
remote:
'origin'
)
fetch
(
branch:
branch
,
depth:
depth
,
remote:
branch_remote
)
fetch
(
branch:
'master'
,
depth:
depth
,
remote:
master_remote
)
merge_base_found?
(
master_remote:
master_remote
,
branch:
branch
)
merge_base_found?
(
branch:
branch
,
branch_remote:
branch_remote
,
master_remote:
master_remote
)
end
raise
"
\n
#{
branch
}
is too far behind
#{
master_remote
}
/master, please rebase it!
\n
"
unless
success
...
...
@@ -274,6 +301,13 @@ module Gitlab
Gitlab
::
Popen
.
popen
(
cmd
)
end
# We're "re-creating" the repo URL because ENV['CI_REPOSITORY_URL'] contains
# redacted credentials (e.g. "***:****") which are useless in instructions
# the job gives.
def
ce_public_repo_url
"
#{
ce_project_url
}
.git"
end
def
applies_cleanly_msg
(
branch
)
%Q{
#{
PLEASE_READ_THIS_BANNER
}
...
...
@@ -288,13 +322,15 @@ module Gitlab
end
def
ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg
ee_repos
=
ee_remotes
.
values
.
uniq
%Q{
#{
PLEASE_READ_THIS_BANNER
}
💥 Oh no! 💥
The `
#{
ce_branch
}
` branch does not apply cleanly to the current
EE/master, and no `
#{
ee_branch_prefix
}
` or `
#{
ee_branch_suffix
}
` branch
was found in
the EE repository
.
was found in
#{
ee_repos
.
join
(
' nor in '
)
}
.
If you're a community contributor, don't worry, someone from
GitLab Inc. will take care of this, and you don't have to do anything.
...
...
@@ -314,17 +350,17 @@ module Gitlab
1. Create a new branch from master and cherry-pick your CE commits
# In the EE repo
$ git fetch
#{
EE_REPO_URL
}
master
$ git fetch
#{
CANONICAL_
EE_REPO_URL
}
master
$ git checkout -b
#{
ee_branch_prefix
}
FETCH_HEAD
$ git fetch
#{
ce_repo_url
}
#{
ce_branch
}
$ git fetch
#{
ce_
public_
repo_url
}
#{
ce_branch
}
$ git cherry-pick SHA # Repeat for all the commits you want to pick
You can squash the `
#{
ce_branch
}
` commits into a single "Port of
#{
ce_branch
}
to EE" commit.
Note:
You can squash the `
#{
ce_branch
}
` commits into a single "Port of
#{
ce_branch
}
to EE" commit.
2. Apply your branch's patch to EE
# In the EE repo
$ git fetch
#{
EE_REPO_URL
}
master
$ git fetch
#{
CANONICAL_
EE_REPO_URL
}
master
$ git checkout -b
#{
ee_branch_prefix
}
FETCH_HEAD
$ wget
#{
patch_url
}
&& git apply --3way
#{
ce_patch_name
}
...
...
@@ -356,10 +392,9 @@ module Gitlab
⚠️ Also, don't forget to create a new merge request on gitlab-ee and
cross-link it with the CE merge request.
Once this is done, you can retry this failed
build
, and it should pass.
Once this is done, you can retry this failed
job
, and it should pass.
Stay 💪 ! For more information, see
https://docs.gitlab.com/ce/development/automatic_ce_ee_merge.html
#{
STAY_STRONG_LINK_TO_DOCS
}
#{
THANKS_FOR_READING_BANNER
}
}
end
...
...
@@ -371,16 +406,15 @@ module Gitlab
The `
#{
ce_branch
}
` does not apply cleanly to the current EE/master, and
even though a `
#{
ee_branch_found
}
` branch
exists in
the EE repository
, it does not apply cleanly either to
exists in
#{
ee_repo_url
}
, it does not apply cleanly either to
EE/master!
#{
conflicting_files_msg
}
Please update the `
#{
ee_branch_found
}
`, push it again to gitlab-ee, and
retry this
build
.
retry this
job
.
Stay 💪 ! For more information, see
https://docs.gitlab.com/ce/development/automatic_ce_ee_merge.html
#{
STAY_STRONG_LINK_TO_DOCS
}
#{
THANKS_FOR_READING_BANNER
}
}
end
...
...
lib/gitlab/git/env.rb
→
lib/gitlab/git/
hook_
env.rb
View file @
9351f7a5
...
...
@@ -3,37 +3,39 @@
module
Gitlab
module
Git
# Ephemeral (per request) storage for environment variables that some Git
# commands
may need
.
# commands
need during internal API calls made from Git push hooks
.
#
# For example, in pre-receive hooks, new objects are put in a temporary
# $GIT_OBJECT_DIRECTORY. Without it set, the new objects cannot be retrieved
# (this would break push rules for instance).
#
# This class is thread-safe via RequestStore.
class
Env
class
Hook
Env
WHITELISTED_VARIABLES
=
%w[
GIT_OBJECT_DIRECTORY
GIT_OBJECT_DIRECTORY_RELATIVE
GIT_ALTERNATE_OBJECT_DIRECTORIES
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
]
.
freeze
def
self
.
set
(
env
)
def
self
.
set
(
gl_repository
,
env
)
return
unless
RequestStore
.
active?
RequestStore
.
store
[
:gitlab_git_env
]
=
whitelist_git_env
(
env
)
raise
"missing gl_repository"
if
gl_repository
.
blank?
RequestStore
.
store
[
:gitlab_git_env
]
||=
{}
RequestStore
.
store
[
:gitlab_git_env
][
gl_repository
]
=
whitelist_git_env
(
env
)
end
def
self
.
all
def
self
.
all
(
gl_repository
)
return
{}
unless
RequestStore
.
active?
RequestStore
.
fetch
(
:gitlab_git_env
)
{
{}
}
h
=
RequestStore
.
fetch
(
:gitlab_git_env
)
{
{}
}
h
.
fetch
(
gl_repository
,
{})
end
def
self
.
to_env_hash
def
self
.
to_env_hash
(
gl_repository
)
env
=
{}
all
.
compact
.
each
do
|
key
,
value
|
all
(
gl_repository
)
.
compact
.
each
do
|
key
,
value
|
value
=
value
.
join
(
File
::
PATH_SEPARATOR
)
if
value
.
is_a?
(
Array
)
env
[
key
.
to_s
]
=
value
end
...
...
@@ -41,10 +43,6 @@ module Gitlab
env
end
def
self
.
[]
(
key
)
all
[
key
]
end
def
self
.
whitelist_git_env
(
env
)
env
.
select
{
|
key
,
_
|
WHITELISTED_VARIABLES
.
include?
(
key
.
to_s
)
}.
with_indifferent_access
end
...
...
lib/gitlab/git/repository.rb
View file @
9351f7a5
...
...
@@ -1759,21 +1759,11 @@ module Gitlab
end
def
alternate_object_directories
relative_paths
=
relative_object_directories
if
relative_paths
.
any?
relative_paths
.
map
{
|
d
|
File
.
join
(
path
,
d
)
}
else
absolute_object_directories
.
flat_map
{
|
d
|
d
.
split
(
File
::
PATH_SEPARATOR
)
}
end
relative_object_directories
.
map
{
|
d
|
File
.
join
(
path
,
d
)
}
end
def
relative_object_directories
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES
).
flatten
.
compact
end
def
absolute_object_directories
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_DIRECTORIES_VARIABLES
).
flatten
.
compact
Gitlab
::
Git
::
HookEnv
.
all
(
gl_repository
).
values_at
(
*
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES
).
flatten
.
compact
end
# Get the content of a blob for a given commit. If the blob is a commit
...
...
lib/gitlab/gitaly_client/util.rb
View file @
9351f7a5
...
...
@@ -3,11 +3,9 @@ module Gitlab
module
Util
class
<<
self
def
repository
(
repository_storage
,
relative_path
,
gl_repository
)
git_object_directory
=
Gitlab
::
Git
::
Env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
presence
||
Gitlab
::
Git
::
Env
[
'GIT_OBJECT_DIRECTORY'
].
presence
git_alternate_object_directories
=
Array
.
wrap
(
Gitlab
::
Git
::
Env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
]).
presence
||
Array
.
wrap
(
Gitlab
::
Git
::
Env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
]).
flat_map
{
|
d
|
d
.
split
(
File
::
PATH_SEPARATOR
)
}
git_env
=
Gitlab
::
Git
::
HookEnv
.
all
(
gl_repository
)
git_object_directory
=
git_env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
presence
git_alternate_object_directories
=
Array
.
wrap
(
git_env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
])
Gitaly
::
Repository
.
new
(
storage_name:
repository_storage
,
...
...
spec/lib/gitlab/git/env_spec.rb
→
spec/lib/gitlab/git/
hook_
env_spec.rb
View file @
9351f7a5
require
'spec_helper'
describe
Gitlab
::
Git
::
Env
do
describe
Gitlab
::
Git
::
HookEnv
do
let
(
:gl_repository
)
{
'project-123'
}
describe
".set"
do
context
'with RequestStore.store disabled'
do
before
do
...
...
@@ -8,9 +10,9 @@ describe Gitlab::Git::Env do
end
it
'does not store anything'
do
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'foo'
)
described_class
.
set
(
gl_repository
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
'foo'
)
expect
(
described_class
.
all
).
to
be_empty
expect
(
described_class
.
all
(
gl_repository
)
).
to
be_empty
end
end
...
...
@@ -21,15 +23,19 @@ describe Gitlab::Git::Env do
it
'whitelist some `GIT_*` variables and stores them using RequestStore'
do
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES
:
'bar'
,
gl_repository
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
:
'bar'
,
GIT_EXEC_PATH
:
'baz'
,
PATH
:
'~/.bin:/bin'
)
expect
(
described_class
[
:GIT_OBJECT_DIRECTORY
]).
to
eq
(
'foo'
)
expect
(
described_class
[
:GIT_ALTERNATE_OBJECT_DIRECTORIES
]).
to
eq
(
'bar'
)
expect
(
described_class
[
:GIT_EXEC_PATH
]).
to
be_nil
expect
(
described_class
[
:bar
]).
to
be_nil
git_env
=
described_class
.
all
(
gl_repository
)
expect
(
git_env
[
:GIT_OBJECT_DIRECTORY_RELATIVE
]).
to
eq
(
'foo'
)
expect
(
git_env
[
:GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
]).
to
eq
(
'bar'
)
expect
(
git_env
[
:GIT_EXEC_PATH
]).
to
be_nil
expect
(
git_env
[
:PATH
]).
to
be_nil
expect
(
git_env
[
:bar
]).
to
be_nil
end
end
end
...
...
@@ -39,14 +45,15 @@ describe Gitlab::Git::Env do
before
do
allow
(
RequestStore
).
to
receive
(
:active?
).
and_return
(
true
)
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES
:
[
'bar'
])
gl_repository
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
:
[
'bar'
])
end
it
'returns an env hash'
do
expect
(
described_class
.
all
).
to
eq
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
[
'bar'
]
expect
(
described_class
.
all
(
gl_repository
)
).
to
eq
({
'GIT_OBJECT_DIRECTORY
_RELATIVE
'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES
_RELATIVE
'
=>
[
'bar'
]
})
end
end
...
...
@@ -56,8 +63,8 @@ describe Gitlab::Git::Env do
context
'with RequestStore.store enabled'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:key
)
{
'GIT_OBJECT_DIRECTORY'
}
subject
{
described_class
.
to_env_hash
}
let
(
:key
)
{
'GIT_OBJECT_DIRECTORY
_RELATIVE
'
}
subject
{
described_class
.
to_env_hash
(
gl_repository
)
}
where
(
:input
,
:output
)
do
nil
|
nil
...
...
@@ -70,7 +77,7 @@ describe Gitlab::Git::Env do
with_them
do
before
do
allow
(
RequestStore
).
to
receive
(
:active?
).
and_return
(
true
)
described_class
.
set
(
key
.
to_sym
=>
input
)
described_class
.
set
(
gl_repository
,
key
.
to_sym
=>
input
)
end
it
'puts the right value in the hash'
do
...
...
@@ -84,47 +91,25 @@ describe Gitlab::Git::Env do
end
end
describe
".[]"
do
context
'with RequestStore.store enabled'
do
before
do
allow
(
RequestStore
).
to
receive
(
:active?
).
and_return
(
true
)
end
before
do
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES
:
'bar'
)
end
it
'returns a stored value for an existing key'
do
expect
(
described_class
[
:GIT_OBJECT_DIRECTORY
]).
to
eq
(
'foo'
)
end
it
'returns nil for an non-existing key'
do
expect
(
described_class
[
:foo
]).
to
be_nil
end
end
end
describe
'thread-safety'
do
context
'with RequestStore.store enabled'
do
before
do
allow
(
RequestStore
).
to
receive
(
:active?
).
and_return
(
true
)
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'foo'
)
described_class
.
set
(
gl_repository
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
'foo'
)
end
it
'is thread-safe'
do
another_thread
=
Thread
.
new
do
described_class
.
set
(
GIT_OBJECT_DIRECTORY
:
'bar'
)
described_class
.
set
(
gl_repository
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
'bar'
)
Thread
.
stop
described_class
[
:GIT_OBJECT_DIRECTORY
]
described_class
.
all
(
gl_repository
)[
:GIT_OBJECT_DIRECTORY_RELATIVE
]
end
# Ensure another_thread runs first
sleep
0.1
until
another_thread
.
stop?
expect
(
described_class
[
:GIT_OBJECT_DIRECTORY
]).
to
eq
(
'foo'
)
expect
(
described_class
.
all
(
gl_repository
)[
:GIT_OBJECT_DIRECTORY_RELATIVE
]).
to
eq
(
'foo'
)
another_thread
.
run
expect
(
another_thread
.
value
).
to
eq
(
'bar'
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
9351f7a5
...
...
@@ -120,7 +120,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe
'alternates keyword argument'
do
context
'with no Git env stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({})
allow
(
Gitlab
::
Git
::
Hook
Env
).
to
receive
(
:all
).
and_return
({})
end
it
"is passed an empty array"
do
...
...
@@ -132,7 +132,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
'with absolute and relative Git object dir envvars stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
allow
(
Gitlab
::
Git
::
Hook
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
'./objects/foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
=>
[
'./objects/bar'
,
'./objects/baz'
],
'GIT_OBJECT_DIRECTORY'
=>
'ignored'
,
...
...
@@ -148,22 +148,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
repository
.
rugged
end
end
context
'with only absolute Git object dir envvars stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
%w[bar baz]
,
'GIT_OTHER'
=>
'another_env'
})
end
it
"is passed the absolute object dir envvars as is"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
%w[foo bar baz]
)
repository
.
rugged
end
end
end
end
...
...
spec/lib/gitlab/git/rev_list_spec.rb
View file @
9351f7a5
...
...
@@ -3,17 +3,6 @@ require 'spec_helper'
describe
Gitlab
::
Git
::
RevList
do
let
(
:repository
)
{
create
(
:project
,
:repository
).
repository
.
raw
}
let
(
:rev_list
)
{
described_class
.
new
(
repository
,
newrev:
'newrev'
)
}
let
(
:env_hash
)
do
{
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'bar'
}
end
let
(
:command_env
)
{
{
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'foo:bar'
}
}
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
(
env_hash
)
end
def
args_for_popen
(
args_list
)
[
Gitlab
.
config
.
git
.
bin_path
,
'rev-list'
,
*
args_list
]
...
...
@@ -23,7 +12,7 @@ describe Gitlab::Git::RevList do
params
=
[
args_for_popen
(
additional_args
),
repository
.
path
,
command_env
,
{}
,
hash_including
(
lazy_block:
with_lazy_block
?
anything
:
nil
)
]
...
...
spec/lib/gitlab/gitaly_client/util_spec.rb
View file @
9351f7a5
...
...
@@ -7,16 +7,19 @@ describe Gitlab::GitalyClient::Util do
let
(
:gl_repository
)
{
'project-1'
}
let
(
:git_object_directory
)
{
'.git/objects'
}
let
(
:git_alternate_object_directory
)
{
[
'/dir/one'
,
'/dir/two'
]
}
let
(
:git_env
)
do
{
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
git_object_directory
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
=>
git_alternate_object_directory
}
end
subject
do
described_class
.
repository
(
repository_storage
,
relative_path
,
gl_repository
)
end
it
'creates a Gitaly::Repository with the given data'
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_OBJECT_DIRECTORY_RELATIVE'
)
.
and_return
(
git_object_directory
)
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
)
.
and_return
(
git_alternate_object_directory
)
allow
(
Gitlab
::
Git
::
HookEnv
).
to
receive
(
:all
).
with
(
gl_repository
).
and_return
(
git_env
)
expect
(
subject
).
to
be_a
(
Gitaly
::
Repository
)
expect
(
subject
.
storage_name
).
to
eq
(
repository_storage
)
...
...
spec/models/ci/artifact_blob_spec.rb
View file @
9351f7a5
...
...
@@ -65,6 +65,19 @@ describe Ci::ArtifactBlob do
expect
(
url
).
not_to
be_nil
expect
(
url
).
to
eq
(
"http://
#{
project
.
namespace
.
path
}
.
#{
Gitlab
.
config
.
pages
.
host
}
/-/
#{
project
.
path
}
/-/jobs/
#{
build
.
id
}
/artifacts/
#{
path
}
"
)
end
context
'when port is configured'
do
let
(
:port
)
{
1234
}
it
'returns an URL with port number'
do
allow
(
Gitlab
.
config
.
pages
).
to
receive
(
:url
).
and_return
(
"
#{
Gitlab
.
config
.
pages
.
url
}
:
#{
port
}
"
)
url
=
subject
.
external_url
(
build
.
project
,
build
)
expect
(
url
).
not_to
be_nil
expect
(
url
).
to
eq
(
"http://
#{
project
.
namespace
.
path
}
.
#{
Gitlab
.
config
.
pages
.
host
}
:
#{
port
}
/-/
#{
project
.
path
}
/-/jobs/
#{
build
.
id
}
/artifacts/
#{
path
}
"
)
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
9351f7a5
...
...
@@ -1398,6 +1398,34 @@ describe Project do
end
end
describe
'#pages_group_url'
do
let
(
:group
)
{
create
:group
,
name:
group_name
}
let
(
:project
)
{
create
:project
,
namespace:
group
,
name:
project_name
}
let
(
:domain
)
{
'Example.com'
}
let
(
:port
)
{
1234
}
subject
{
project
.
pages_group_url
}
before
do
allow
(
Settings
.
pages
).
to
receive
(
:host
).
and_return
(
domain
)
allow
(
Gitlab
.
config
.
pages
).
to
receive
(
:url
).
and_return
(
"http://example.com:
#{
port
}
"
)
end
context
'group page'
do
let
(
:group_name
)
{
'Group'
}
let
(
:project_name
)
{
'group.example.com'
}
it
{
is_expected
.
to
eq
(
"http://group.example.com:
#{
port
}
"
)
}
end
context
'project page'
do
let
(
:group_name
)
{
'Group'
}
let
(
:project_name
)
{
'Project'
}
it
{
is_expected
.
to
eq
(
"http://group.example.com:
#{
port
}
"
)
}
end
end
describe
'.search'
do
let
(
:project
)
{
create
(
:project
,
description:
'kitten mittens'
)
}
...
...
spec/requests/api/internal_spec.rb
View file @
9351f7a5
...
...
@@ -251,44 +251,23 @@ describe API::Internal do
end
context
'with env passed as a JSON'
do
context
'when relative path envs are not set'
do
it
'sets env in RequestStore'
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:set
).
with
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'bar'
})
push
(
key
,
project
.
wiki
,
env:
{
GIT_OBJECT_DIRECTORY
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES
:
'bar'
}.
to_json
)
let
(
:gl_repository
)
{
project
.
gl_repository
(
is_wiki:
true
)
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'sets env in RequestStore'
do
obj_dir_relative
=
'./objects'
alt_obj_dirs_relative
=
[
'./alt-objects-1'
,
'./alt-objects-2'
]
context
'when relative path envs are set'
do
it
'sets env in RequestStore'
do
obj_dir_relative
=
'./objects'
alt_obj_dirs_relative
=
[
'./alt-objects-1'
,
'./alt-objects-2'
]
repo_path
=
project
.
wiki
.
repository
.
path_to_repo
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:set
).
with
({
'GIT_OBJECT_DIRECTORY'
=>
File
.
join
(
repo_path
,
obj_dir_relative
),
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
alt_obj_dirs_relative
.
map
{
|
d
|
File
.
join
(
repo_path
,
d
)
},
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
obj_dir_relative
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
=>
alt_obj_dirs_relative
})
push
(
key
,
project
.
wiki
,
env:
{
GIT_OBJECT_DIRECTORY
:
'foo'
,
GIT_ALTERNATE_OBJECT_DIRECTORIES
:
'bar'
,
GIT_OBJECT_DIRECTORY_RELATIVE
:
obj_dir_relative
,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
:
alt_obj_dirs_relative
}.
to_json
)
expect
(
Gitlab
::
Git
::
HookEnv
).
to
receive
(
:set
).
with
(
gl_repository
,
{
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
obj_dir_relative
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
=>
alt_obj_dirs_relative
})
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
push
(
key
,
project
.
wiki
,
env:
{
GIT_OBJECT_DIRECTORY_RELATIVE
:
obj_dir_relative
,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
:
alt_obj_dirs_relative
}.
to_json
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment