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
6ae1a73c
Commit
6ae1a73c
authored
Dec 07, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass source_branch properly for cherry-pick/revert
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237/diffs#note_19210818
parent
65806ec6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
16 deletions
+21
-16
repository.rb
app/models/repository.rb
+8
-4
change_service.rb
app/services/commits/change_service.rb
+8
-1
git_operation_service.rb
app/services/git_operation_service.rb
+5
-11
No files found.
app/models/repository.rb
View file @
6ae1a73c
...
...
@@ -962,14 +962,16 @@ class Repository
end
end
def
revert
(
user
,
commit
,
base_branch
,
revert_tree_id
=
nil
)
def
revert
(
user
,
commit
,
base_branch
,
revert_tree_id
=
nil
,
source_branch:
nil
,
source_project:
project
)
revert_tree_id
||=
check_revert_content
(
commit
,
base_branch
)
return
false
unless
revert_tree_id
GitOperationService
.
new
(
user
,
self
).
with_branch
(
base_branch
,
source_
commit:
commi
t
)
do
source_
branch:
source_branch
,
source_project:
source_projec
t
)
do
source_sha
=
find_branch
(
base_branch
).
dereferenced_target
.
sha
committer
=
user_to_committer
(
user
)
...
...
@@ -983,14 +985,16 @@ class Repository
end
end
def
cherry_pick
(
user
,
commit
,
base_branch
,
cherry_pick_tree_id
=
nil
)
def
cherry_pick
(
user
,
commit
,
base_branch
,
cherry_pick_tree_id
=
nil
,
source_branch:
nil
,
source_project:
project
)
cherry_pick_tree_id
||=
check_cherry_pick_content
(
commit
,
base_branch
)
return
false
unless
cherry_pick_tree_id
GitOperationService
.
new
(
user
,
self
).
with_branch
(
base_branch
,
source_
commit:
commi
t
)
do
source_
branch:
source_branch
,
source_project:
source_projec
t
)
do
source_sha
=
find_branch
(
base_branch
).
dereferenced_target
.
sha
committer
=
user_to_committer
(
user
)
...
...
app/services/commits/change_service.rb
View file @
6ae1a73c
...
...
@@ -31,7 +31,14 @@ module Commits
if
tree_id
validate_target_branch
(
into
)
if
@create_merge_request
repository
.
public_send
(
action
,
current_user
,
@commit
,
into
,
tree_id
)
repository
.
public_send
(
action
,
current_user
,
@commit
,
into
,
tree_id
,
source_branch:
@target_branch
)
success
else
error_msg
=
"Sorry, we cannot
#{
action
.
to_s
.
dasherize
}
this
#{
@commit
.
change_type_title
}
automatically.
...
...
app/services/git_operation_service.rb
View file @
6ae1a73c
...
...
@@ -25,21 +25,15 @@ GitOperationService = Struct.new(:user, :repository) do
end
end
# Whenever `source_branch` or `source_commit` is passed, if `branch`
# doesn't exist, it would be created from `source_branch` or
# `source_commit`. Should only pass one of them, not both.
# Whenever `source_branch` is passed, if `branch` doesn't exist,
# it would be created from `source_branch`.
# If `source_project` is passed, and the branch doesn't exist,
# it would try to find the source from it instead of current repository.
def
with_branch
(
branch_name
,
source_branch:
nil
,
source_commit:
nil
,
source_project:
repository
.
project
)
if
source_commit
&&
source_branch
raise
ArgumentError
,
'Should pass only :source_branch or :source_commit'
end
ref
=
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
branch_name
oldrev
=
Gitlab
::
Git
::
BLANK_SHA
...
...
@@ -62,13 +56,13 @@ GitOperationService = Struct.new(:user, :repository) do
"
#{
source_project
.
path_with_namespace
}
"
)
end
elsif
source_
commit
||
source_
branch
newrev
=
(
source_commit
||
repository
.
commit
(
source_branch
)
).
try
(
:sha
)
elsif
source_branch
newrev
=
repository
.
commit
(
source_branch
).
try
(
:sha
)
unless
newrev
raise
Repository
::
CommitError
.
new
(
"Cannot find branch
#{
branch_name
}
nor"
\
"
#{
source_
commit
.
try
(
:sha
)
||
source_
branch
}
from"
\
"
#{
source_branch
}
from"
\
"
#{
repository
.
project
.
path_with_namespace
}
"
)
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