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