Commit 9ea37cda authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

merge with support of pre-receive and post-receive hooks

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f4149bcd
...@@ -392,7 +392,7 @@ class Repository ...@@ -392,7 +392,7 @@ class Repository
end end
def remove_file(user, path, message, branch) def remove_file(user, path, message, branch)
commit_with_hooks(user, branch) do |branch| commit_with_hooks(user, branch) do |ref|
path[0] = '' if path[0] == '/' path[0] = '' if path[0] == '/'
committer = user_to_comitter(user) committer = user_to_comitter(user)
...@@ -431,7 +431,7 @@ class Repository ...@@ -431,7 +431,7 @@ class Repository
end end
end end
def merge(source_sha, target_branch, options = {}) def merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha) their_commit = rugged.lookup(source_sha)
...@@ -441,14 +441,16 @@ class Repository ...@@ -441,14 +441,16 @@ class Repository
merge_index = rugged.merge_commits(our_commit, their_commit) merge_index = rugged.merge_commits(our_commit, their_commit)
return false if merge_index.conflicts? return false if merge_index.conflicts?
commit_with_hooks(user, target_branch) do |ref|
actual_options = options.merge( actual_options = options.merge(
parents: [our_commit, their_commit], parents: [our_commit, their_commit],
tree: merge_index.write_tree(rugged), tree: merge_index.write_tree(rugged),
update_ref: "refs/heads/#{target_branch}" update_ref: ref
) )
Rugged::Commit.create(rugged, actual_options) Rugged::Commit.create(rugged, actual_options)
end end
end
def search_files(query, ref) def search_files(query, ref)
offset = 2 offset = 2
......
...@@ -17,7 +17,7 @@ module MergeRequests ...@@ -17,7 +17,7 @@ module MergeRequests
end end
merge_request.in_locked_state do merge_request.in_locked_state do
if merge_changes if commit
after_merge after_merge
success success
else else
...@@ -28,12 +28,6 @@ module MergeRequests ...@@ -28,12 +28,6 @@ module MergeRequests
private private
def merge_changes
if sha = commit
after_commit(sha, merge_request.target_branch)
end
end
def commit def commit
committer = repository.user_to_comitter(current_user) committer = repository.user_to_comitter(current_user)
...@@ -43,11 +37,7 @@ module MergeRequests ...@@ -43,11 +37,7 @@ module MergeRequests
committer: committer committer: committer
} }
repository.merge(merge_request.source_sha, merge_request.target_branch, options) repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
end
def after_commit(sha, branch)
PostCommitService.new(project, current_user).execute(sha, branch)
end end
def after_merge def after_merge
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment