BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ccc73c45
Commit
ccc73c45
authored
Jan 06, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename from base to start because base could mean merge base
parent
e3c36850
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
91 additions
and
91 deletions
+91
-91
creates_commit.rb
app/controllers/concerns/creates_commit.rb
+3
-3
repository.rb
app/models/repository.rb
+39
-39
change_service.rb
app/services/commits/change_service.rb
+5
-5
compare_service.rb
app/services/compare_service.rb
+6
-6
base_service.rb
app/services/files/base_service.rb
+5
-5
create_dir_service.rb
app/services/files/create_dir_service.rb
+2
-2
create_service.rb
app/services/files/create_service.rb
+3
-3
delete_service.rb
app/services/files/delete_service.rb
+2
-2
multi_service.rb
app/services/files/multi_service.rb
+3
-3
update_service.rb
app/services/files/update_service.rb
+3
-3
git_operation_service.rb
app/services/git_operation_service.rb
+20
-20
No files found.
app/controllers/concerns/creates_commit.rb
View file @
ccc73c45
...
...
@@ -4,10 +4,10 @@ module CreatesCommit
def
create_commit
(
service
,
success_path
:,
failure_path
:,
failure_view:
nil
,
success_notice:
nil
)
set_commit_variables
base
_branch
=
@mr_target_branch
unless
initial_commit?
start
_branch
=
@mr_target_branch
unless
initial_commit?
commit_params
=
@commit_params
.
merge
(
base
_project:
@mr_target_project
,
base_branch:
base
_branch
,
start
_project:
@mr_target_project
,
start_branch:
start
_branch
,
target_branch:
@mr_source_branch
)
...
...
app/models/repository.rb
View file @
ccc73c45
...
...
@@ -748,12 +748,12 @@ class Repository
user
,
path
,
message
:,
branch_name
:,
author_email:
nil
,
author_name:
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
check_tree_entry_for_dir
(
branch_name
,
path
)
if
base
_branch_name
base
_project
.
repository
.
check_tree_entry_for_dir
(
base
_branch_name
,
path
)
if
start
_branch_name
start
_project
.
repository
.
check_tree_entry_for_dir
(
start
_branch_name
,
path
)
end
commit_file
(
...
...
@@ -765,8 +765,8 @@ class Repository
update:
false
,
author_email:
author_email
,
author_name:
author_name
,
base_branch_name:
base
_branch_name
,
base_project:
base
_project
)
start_branch_name:
start
_branch_name
,
start_project:
start
_project
)
end
# rubocop:enable Metrics/ParameterLists
...
...
@@ -775,7 +775,7 @@ class Repository
user
,
path
,
content
,
message
:,
branch_name
:,
update:
true
,
author_email:
nil
,
author_name:
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
unless
update
error_message
=
"Filename already exists; update not allowed"
...
...
@@ -783,8 +783,8 @@ class Repository
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
error_message
)
end
if
base
_branch_name
&&
base_project
.
repository
.
tree_entry_at
(
base
_branch_name
,
path
)
if
start
_branch_name
&&
start_project
.
repository
.
tree_entry_at
(
start
_branch_name
,
path
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
error_message
)
end
end
...
...
@@ -795,8 +795,8 @@ class Repository
branch_name:
branch_name
,
author_email:
author_email
,
author_name:
author_name
,
base_branch_name:
base
_branch_name
,
base_project:
base
_project
,
start_branch_name:
start
_branch_name
,
start_project:
start
_project
,
actions:
[{
action: :create
,
file_path:
path
,
content:
content
}])
...
...
@@ -808,7 +808,7 @@ class Repository
user
,
path
,
content
,
message
:,
branch_name
:,
previous_path
:,
author_email:
nil
,
author_name:
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
action
=
if
previous_path
&&
previous_path
!=
path
:move
else
...
...
@@ -821,8 +821,8 @@ class Repository
branch_name:
branch_name
,
author_email:
author_email
,
author_name:
author_name
,
base_branch_name:
base
_branch_name
,
base_project:
base
_project
,
start_branch_name:
start
_branch_name
,
start_project:
start
_project
,
actions:
[{
action:
action
,
file_path:
path
,
content:
content
,
...
...
@@ -835,15 +835,15 @@ class Repository
user
,
path
,
message
:,
branch_name
:,
author_email:
nil
,
author_name:
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
multi_action
(
user:
user
,
message:
message
,
branch_name:
branch_name
,
author_email:
author_email
,
author_name:
author_name
,
base_branch_name:
base
_branch_name
,
base_project:
base
_project
,
start_branch_name:
start
_branch_name
,
start_project:
start
_project
,
actions:
[{
action: :delete
,
file_path:
path
}])
end
...
...
@@ -853,16 +853,16 @@ class Repository
def
multi_action
(
user
:,
branch_name
:,
message
:,
actions
:,
author_email:
nil
,
author_name:
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
GitOperationService
.
new
(
user
,
self
).
with_branch
(
branch_name
,
base_branch_name:
base
_branch_name
,
base_project:
base_project
)
do
|
base
_commit
|
start_branch_name:
start
_branch_name
,
start_project:
start_project
)
do
|
start
_commit
|
index
=
rugged
.
index
parents
=
if
base
_commit
index
.
read_tree
(
base
_commit
.
raw_commit
.
tree
)
[
base
_commit
.
sha
]
parents
=
if
start
_commit
index
.
read_tree
(
start
_commit
.
raw_commit
.
tree
)
[
start
_commit
.
sha
]
else
[]
end
...
...
@@ -910,8 +910,8 @@ class Repository
def
merge
(
user
,
merge_request
,
options
=
{})
GitOperationService
.
new
(
user
,
self
).
with_branch
(
merge_request
.
target_branch
)
do
|
base
_commit
|
our_commit
=
base
_commit
.
sha
merge_request
.
target_branch
)
do
|
start
_commit
|
our_commit
=
start
_commit
.
sha
their_commit
=
merge_request
.
diff_head_sha
raise
'Invalid merge target'
unless
our_commit
...
...
@@ -935,15 +935,15 @@ class Repository
def
revert
(
user
,
commit
,
branch_name
,
revert_tree_id
=
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
revert_tree_id
||=
check_revert_content
(
commit
,
branch_name
)
return
false
unless
revert_tree_id
GitOperationService
.
new
(
user
,
self
).
with_branch
(
branch_name
,
base_branch_name:
base
_branch_name
,
base_project:
base_project
)
do
|
base
_commit
|
start_branch_name:
start
_branch_name
,
start_project:
start_project
)
do
|
start
_commit
|
committer
=
user_to_committer
(
user
)
...
...
@@ -952,21 +952,21 @@ class Repository
author:
committer
,
committer:
committer
,
tree:
revert_tree_id
,
parents:
[
base
_commit
.
sha
])
parents:
[
start
_commit
.
sha
])
end
end
def
cherry_pick
(
user
,
commit
,
branch_name
,
cherry_pick_tree_id
=
nil
,
base_branch_name:
nil
,
base
_project:
project
)
start_branch_name:
nil
,
start
_project:
project
)
cherry_pick_tree_id
||=
check_cherry_pick_content
(
commit
,
branch_name
)
return
false
unless
cherry_pick_tree_id
GitOperationService
.
new
(
user
,
self
).
with_branch
(
branch_name
,
base_branch_name:
base
_branch_name
,
base_project:
base_project
)
do
|
base
_commit
|
start_branch_name:
start
_branch_name
,
start_project:
start_project
)
do
|
start
_commit
|
committer
=
user_to_committer
(
user
)
...
...
@@ -979,7 +979,7 @@ class Repository
},
committer:
committer
,
tree:
cherry_pick_tree_id
,
parents:
[
base
_commit
.
sha
])
parents:
[
start
_commit
.
sha
])
end
end
...
...
@@ -1066,20 +1066,20 @@ class Repository
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
lines
.
map
(
&
:strip
)
end
def
with_repo_branch_commit
(
base_repository
,
base
_branch_name
)
def
with_repo_branch_commit
(
start_repository
,
start
_branch_name
)
branch_name_or_sha
=
if
base
_repository
==
self
base
_branch_name
if
start
_repository
==
self
start
_branch_name
else
tmp_ref
=
"refs/tmp/
#{
SecureRandom
.
hex
}
/head"
fetch_ref
(
base
_repository
.
path_to_repo
,
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
base
_branch_name
}
"
,
start
_repository
.
path_to_repo
,
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
start
_branch_name
}
"
,
tmp_ref
)
base_repository
.
commit
(
base
_branch_name
).
sha
start_repository
.
commit
(
start
_branch_name
).
sha
end
yield
(
commit
(
branch_name_or_sha
))
...
...
app/services/commits/change_service.rb
View file @
ccc73c45
...
...
@@ -4,8 +4,8 @@ module Commits
class
ChangeError
<
StandardError
;
end
def
execute
@
base_project
=
params
[
:base
_project
]
||
@project
@
base_branch
=
params
[
:base
_branch
]
@
start_project
=
params
[
:start
_project
]
||
@project
@
start_branch
=
params
[
:start
_branch
]
@target_branch
=
params
[
:target_branch
]
@commit
=
params
[
:commit
]
@create_merge_request
=
params
[
:create_merge_request
].
present?
...
...
@@ -28,7 +28,7 @@ module Commits
if
@create_merge_request
into
=
@commit
.
public_send
(
"
#{
action
}
_branch_name"
)
tree_branch
=
@
base
_branch
tree_branch
=
@
start
_branch
else
into
=
tree_branch
=
@target_branch
end
...
...
@@ -45,8 +45,8 @@ module Commits
@commit
,
into
,
tree_id
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
)
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
success
else
...
...
app/services/compare_service.rb
View file @
ccc73c45
...
...
@@ -3,18 +3,18 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs
class
CompareService
attr_reader
:
base_project
,
:base
_branch_name
attr_reader
:
start_project
,
:start
_branch_name
def
initialize
(
new_
base_project
,
new_base
_branch_name
)
@
base_project
=
new_base
_project
@
base_branch_name
=
new_base
_branch_name
def
initialize
(
new_
start_project
,
new_start
_branch_name
)
@
start_project
=
new_start
_project
@
start_branch_name
=
new_start
_branch_name
end
def
execute
(
target_project
,
target_branch
,
straight:
false
)
# If compare with other project we need to fetch ref first
target_project
.
repository
.
with_repo_branch_commit
(
base
_project
.
repository
,
base
_branch_name
)
do
|
commit
|
start
_project
.
repository
,
start
_branch_name
)
do
|
commit
|
break
unless
commit
compare
(
commit
.
sha
,
target_project
,
target_branch
,
straight
)
...
...
app/services/files/base_service.rb
View file @
ccc73c45
...
...
@@ -3,8 +3,8 @@ module Files
class
ValidationError
<
StandardError
;
end
def
execute
@
base_project
=
params
[
:base
_project
]
||
@project
@
base_branch
=
params
[
:base
_branch
]
@
start_project
=
params
[
:start
_project
]
||
@project
@
start_branch
=
params
[
:start
_branch
]
@target_branch
=
params
[
:target_branch
]
@commit_message
=
params
[
:commit_message
]
...
...
@@ -22,7 +22,7 @@ module Files
# Validate parameters
validate
# Create new branch if it different from
base
_branch
# Create new branch if it different from
start
_branch
validate_target_branch
if
different_branch?
result
=
commit
...
...
@@ -38,7 +38,7 @@ module Files
private
def
different_branch?
@
base_branch
!=
@target_branch
||
@base
_project
!=
@project
@
start_branch
!=
@target_branch
||
@start
_project
!=
@project
end
def
file_has_changed?
...
...
@@ -59,7 +59,7 @@ module Files
end
unless
project
.
empty_repo?
unless
@
base_project
.
repository
.
branch_exists?
(
@base
_branch
)
unless
@
start_project
.
repository
.
branch_exists?
(
@start
_branch
)
raise_error
(
'You can only create or edit files when you are on a branch'
)
end
...
...
app/services/files/create_dir_service.rb
View file @
ccc73c45
...
...
@@ -8,8 +8,8 @@ module Files
branch_name:
@target_branch
,
author_email:
@author_email
,
author_name:
@author_name
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
)
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
end
def
validate
...
...
app/services/files/create_service.rb
View file @
ccc73c45
...
...
@@ -10,8 +10,8 @@ module Files
update:
false
,
author_email:
@author_email
,
author_name:
@author_name
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
)
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
end
def
validate
...
...
@@ -34,7 +34,7 @@ module Files
unless
project
.
empty_repo?
@file_path
.
slice!
(
0
)
if
@file_path
.
start_with?
(
'/'
)
blob
=
repository
.
blob_at_branch
(
@
base
_branch
,
@file_path
)
blob
=
repository
.
blob_at_branch
(
@
start
_branch
,
@file_path
)
if
blob
raise_error
(
'Your changes could not be committed because a file with the same name already exists'
)
...
...
app/services/files/delete_service.rb
View file @
ccc73c45
...
...
@@ -8,8 +8,8 @@ module Files
branch_name:
@target_branch
,
author_email:
@author_email
,
author_name:
@author_name
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
)
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
end
end
end
app/services/files/multi_service.rb
View file @
ccc73c45
...
...
@@ -10,8 +10,8 @@ module Files
actions:
params
[
:actions
],
author_email:
@author_email
,
author_name:
@author_name
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
end
...
...
@@ -63,7 +63,7 @@ module Files
end
def
last_commit
Gitlab
::
Git
::
Commit
.
last_for_path
(
repository
,
@
base
_branch
,
@file_path
)
Gitlab
::
Git
::
Commit
.
last_for_path
(
repository
,
@
start
_branch
,
@file_path
)
end
def
regex_check
(
file
)
...
...
app/services/files/update_service.rb
View file @
ccc73c45
...
...
@@ -9,8 +9,8 @@ module Files
previous_path:
@previous_path
,
author_email:
@author_email
,
author_name:
@author_name
,
base_project:
@base
_project
,
base_branch_name:
@base
_branch
)
start_project:
@start
_project
,
start_branch_name:
@start
_branch
)
end
private
...
...
@@ -25,7 +25,7 @@ module Files
def
last_commit
@last_commit
||=
Gitlab
::
Git
::
Commit
.
last_for_path
(
@
base_project
.
repository
,
@base
_branch
,
@file_path
)
last_for_path
(
@
start_project
.
repository
,
@start
_branch
,
@file_path
)
end
end
end
app/services/git_operation_service.rb
View file @
ccc73c45
...
...
@@ -46,23 +46,23 @@ class GitOperationService
end
end
# Whenever `
base
_branch_name` is passed, if `branch_name` doesn't exist,
# it would be created from `
base
_branch_name`.
# If `
base
_project` is passed, and the branch doesn't exist,
# it would try to find the
base
from it instead of current repository.
# Whenever `
start
_branch_name` is passed, if `branch_name` doesn't exist,
# it would be created from `
start
_branch_name`.
# If `
start
_project` is passed, and the branch doesn't exist,
# it would try to find the
commits
from it instead of current repository.
def
with_branch
(
branch_name
,
base
_branch_name:
nil
,
base
_project:
repository
.
project
,
start
_branch_name:
nil
,
start
_project:
repository
.
project
,
&
block
)
check_with_branch_arguments!
(
branch_name
,
base_branch_name
,
base
_project
)
branch_name
,
start_branch_name
,
start
_project
)
update_branch_with_hooks
(
branch_name
)
do
repository
.
with_repo_branch_commit
(
base
_project
.
repository
,
base
_branch_name
||
branch_name
,
start
_project
.
repository
,
start
_branch_name
||
branch_name
,
&
block
)
end
end
...
...
@@ -148,27 +148,27 @@ class GitOperationService
end
def
check_with_branch_arguments!
(
branch_name
,
base_branch_name
,
base
_project
)
branch_name
,
start_branch_name
,
start
_project
)
return
if
repository
.
branch_exists?
(
branch_name
)
if
repository
.
project
!=
base
_project
unless
base
_branch_name
if
repository
.
project
!=
start
_project
unless
start
_branch_name
raise
ArgumentError
,
'Should also pass :
base
_branch_name if'
+
' :
base
_project is different from current project'
'Should also pass :
start
_branch_name if'
+
' :
start
_project is different from current project'
end
unless
base_project
.
repository
.
branch_exists?
(
base
_branch_name
)
unless
start_project
.
repository
.
branch_exists?
(
start
_branch_name
)
raise
ArgumentError
,
"Cannot find branch
#{
branch_name
}
nor"
\
"
#{
base
_branch_name
}
from"
\
"
#{
base
_project
.
path_with_namespace
}
"
"
#{
start
_branch_name
}
from"
\
"
#{
start
_project
.
path_with_namespace
}
"
end
elsif
base
_branch_name
unless
repository
.
branch_exists?
(
base
_branch_name
)
elsif
start
_branch_name
unless
repository
.
branch_exists?
(
start
_branch_name
)
raise
ArgumentError
,
"Cannot find branch
#{
branch_name
}
nor"
\
"
#{
base
_branch_name
}
from"
\
"
#{
start
_branch_name
}
from"
\
"
#{
repository
.
project
.
path_with_namespace
}
"
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