#222: init GitHook on creating branch from UI

This commit is contained in:
Vokhmin Alexey V 2013-07-22 18:21:12 +04:00
parent 6f748e9baf
commit 079f8a955a
2 changed files with 11 additions and 10 deletions

View File

@ -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

View File

@ -34,16 +34,17 @@ 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)