#222: init GitHook on creating branch from UI
This commit is contained in:
parent
6f748e9baf
commit
079f8a955a
|
@ -35,12 +35,12 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def restore_branch
|
def restore_branch
|
||||||
@project.restore_branch @treeish, params[:sha] if @treeish.present? && params[:sha].present?
|
status = @project.restore_branch(@treeish, params[:sha], current_user) ? 200 : 422
|
||||||
render :nothing => true
|
render :nothing => true, :status => status
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
status = @project.create_branch(params[:new_ref], params[:from_ref]) ? 200 : 422
|
status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422
|
||||||
render :nothing => true, :status => status
|
render :nothing => true, :status => status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,23 +34,24 @@ module Modules
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: return something else instead of empty string on success and error
|
# TODO: return something else instead of empty string on success and error
|
||||||
def restore_branch(branch, sha)
|
def restore_branch(branch, sha, user)
|
||||||
|
return false if branch.blank? || sha.blank?
|
||||||
repo.git.native(:branch, {}, branch, sha)
|
repo.git.native(:branch, {}, branch, sha)
|
||||||
|
Resque.enqueue(GitHook, owner.uname, name, sha, GitHook::ZERO, "refs/heads/#{branch}", 'commit', "user-#{user.id}", nil)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_branch(new_ref, from_ref)
|
def create_branch(new_ref, from_ref, user)
|
||||||
return false if new_ref.blank? || from_ref.blank? ||
|
branch = repo.branches.detect{|b| b.name == from_ref}
|
||||||
repo.branches.none?{|b| b.name == from_ref} ||
|
return false if !branch || repo.branches.one?{|b| b.name == new_ref}
|
||||||
repo.branches.one?{|b| b.name == new_ref}
|
restore_branch new_ref, branch.commit.id, user
|
||||||
restore_branch new_ref, from_ref
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_branch(branch, user)
|
def delete_branch(branch, user)
|
||||||
return false if default_branch == branch.name
|
return false if default_branch == branch.name
|
||||||
message = repo.git.native(:branch, {}, '-D', branch.name)
|
message = repo.git.native(:branch, {}, '-D', branch.name)
|
||||||
if message.present?
|
if message.present?
|
||||||
Resque.enqueue(GitHook,owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
|
Resque.enqueue(GitHook, owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
|
||||||
end
|
end
|
||||||
return message.present?
|
return message.present?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue