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
325a2fb7
Commit
325a2fb7
authored
Feb 06, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract some EE-specific functionality in app/models/repository.rb
parent
7fb9d56a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
63 deletions
+64
-63
app/models/concerns/repository_mirroring.rb
app/models/concerns/repository_mirroring.rb
+61
-0
app/models/repository.rb
app/models/repository.rb
+1
-62
spec/models/remote_mirror_spec.rb
spec/models/remote_mirror_spec.rb
+2
-1
No files found.
app/models/concerns/repository_mirroring.rb
0 → 100644
View file @
325a2fb7
module
RepositoryMirroring
def
storage_path
@project
.
repository_storage_path
end
def
push_remote_branches
(
remote
,
branches
)
gitlab_shell
.
push_remote_branches
(
storage_path
,
path_with_namespace
,
remote
,
branches
)
end
def
delete_remote_branches
(
remote
,
branches
)
gitlab_shell
.
delete_remote_branches
(
storage_path
,
path_with_namespace
,
remote
,
branches
)
end
def
add_remote
(
name
,
url
)
raw_repository
.
remote_add
(
name
,
url
)
rescue
Rugged
::
ConfigError
raw_repository
.
remote_update
(
name
,
url:
url
)
end
def
remove_remote
(
name
)
raw_repository
.
remote_delete
(
name
)
true
rescue
Rugged
::
ConfigError
false
end
def
set_remote_as_mirror
(
name
)
config
=
raw_repository
.
rugged
.
config
# This is used by Gitlab Geo to define repository as equivalent as "git clone --mirror"
config
[
"remote.
#{
name
}
.fetch"
]
=
'refs/*:refs/*'
config
[
"remote.
#{
name
}
.mirror"
]
=
true
config
[
"remote.
#{
name
}
.prune"
]
=
true
end
def
fetch_remote
(
remote
,
forced:
false
,
no_tags:
false
)
gitlab_shell
.
fetch_remote
(
storage_path
,
path_with_namespace
,
remote
,
forced:
forced
,
no_tags:
no_tags
)
end
def
remote_tags
(
remote
)
gitlab_shell
.
list_remote_tags
(
storage_path
,
path_with_namespace
,
remote
).
map
do
|
name
,
target
|
Gitlab
::
Git
::
Tag
.
new
(
raw_repository
,
name
,
target
)
end
end
def
remote_branches
(
remote_name
)
branches
=
[]
rugged
.
references
.
each
(
"refs/remotes/
#{
remote_name
}
/*"
).
map
do
|
ref
|
name
=
ref
.
name
.
sub
(
/\Arefs\/remotes\/
#{
remote_name
}
\//
,
''
)
begin
branches
<<
Gitlab
::
Git
::
Branch
.
new
(
raw_repository
,
name
,
ref
.
target
)
rescue
Rugged
::
ReferenceError
# Omit invalid branch
end
end
branches
end
end
app/models/repository.rb
View file @
325a2fb7
...
...
@@ -5,6 +5,7 @@ require 'forwardable'
class
Repository
include
Gitlab
::
ShellAdapter
include
Elastic
::
RepositoriesSearch
include
RepositoryMirroring
attr_accessor
:path_with_namespace
,
:project
...
...
@@ -70,10 +71,6 @@ class Repository
@raw_repository
||=
Gitlab
::
Git
::
Repository
.
new
(
path_to_repo
)
end
def
storage_path
@project
.
repository_storage_path
end
# Return absolute path to repository
def
path_to_repo
@path_to_repo
||=
File
.
expand_path
(
...
...
@@ -185,10 +182,6 @@ class Repository
find_branch
(
branch_name
)
end
def
push_remote_branches
(
remote
,
branches
)
gitlab_shell
.
push_remote_branches
(
storage_path
,
path_with_namespace
,
remote
,
branches
)
end
def
add_tag
(
user
,
tag_name
,
target
,
message
=
nil
)
newrev
=
commit
(
target
).
try
(
:id
)
options
=
{
message:
message
,
tagger:
user_to_committer
(
user
)
}
if
message
...
...
@@ -210,10 +203,6 @@ class Repository
true
end
def
delete_remote_branches
(
remote
,
branches
)
gitlab_shell
.
delete_remote_branches
(
storage_path
,
path_with_namespace
,
remote
,
branches
)
end
def
rm_tag
(
user
,
tag_name
)
before_remove_tag
tag
=
find_tag
(
tag_name
)
...
...
@@ -224,40 +213,6 @@ class Repository
true
end
def
config
raw_repository
.
rugged
.
config
end
def
add_remote
(
name
,
url
)
raw_repository
.
remote_add
(
name
,
url
)
rescue
Rugged
::
ConfigError
raw_repository
.
remote_update
(
name
,
url:
url
)
end
def
remove_remote
(
name
)
raw_repository
.
remote_delete
(
name
)
true
rescue
Rugged
::
ConfigError
false
end
def
set_remote_as_mirror
(
name
)
# This is used by Gitlab Geo to define repository as equivalent as "git clone --mirror"
config
[
"remote.
#{
name
}
.fetch"
]
=
'refs/*:refs/*'
config
[
"remote.
#{
name
}
.mirror"
]
=
true
config
[
"remote.
#{
name
}
.prune"
]
=
true
end
def
fetch_remote
(
remote
,
forced:
false
,
no_tags:
false
)
gitlab_shell
.
fetch_remote
(
storage_path
,
path_with_namespace
,
remote
,
forced:
forced
,
no_tags:
no_tags
)
end
def
remote_tags
(
remote
)
gitlab_shell
.
list_remote_tags
(
storage_path
,
path_with_namespace
,
remote
).
map
do
|
name
,
target
|
Gitlab
::
Git
::
Tag
.
new
(
raw_repository
,
name
,
target
)
end
end
def
ref_names
branch_names
+
tag_names
end
...
...
@@ -805,22 +760,6 @@ class Repository
alias_method
:branches
,
:local_branches
def
remote_branches
(
remote_name
)
branches
=
[]
rugged
.
references
.
each
(
"refs/remotes/
#{
remote_name
}
/*"
).
map
do
|
ref
|
name
=
ref
.
name
.
sub
(
/\Arefs\/remotes\/
#{
remote_name
}
\//
,
''
)
begin
branches
<<
Gitlab
::
Git
::
Branch
.
new
(
raw_repository
,
name
,
ref
.
target
)
rescue
Rugged
::
ReferenceError
# Omit invalid branch
end
end
branches
end
def
tags
@tags
||=
raw_repository
.
tags
end
...
...
spec/models/remote_mirror_spec.rb
View file @
325a2fb7
...
...
@@ -50,7 +50,8 @@ describe RemoteMirror do
mirror
.
update_attribute
(
:url
,
'http://foo:baz@test.com'
)
expect
(
repo
.
config
[
"remote.
#{
mirror
.
ref_name
}
.url"
]).
to
eq
(
'http://foo:baz@test.com'
)
config
=
repo
.
raw_repository
.
rugged
.
config
expect
(
config
[
"remote.
#{
mirror
.
ref_name
}
.url"
]).
to
eq
(
'http://foo:baz@test.com'
)
end
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