#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
def restore_branch
@project.restore_branch @treeish, params[:sha] if @treeish.present? && params[:sha].present?
render :nothing => true
status = @project.restore_branch(@treeish, params[:sha], current_user) ? 200 : 422
render :nothing => true, :status => status
end
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
end

View File

@ -34,16 +34,17 @@ module Modules
end
# 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)
Resque.enqueue(GitHook, owner.uname, name, sha, GitHook::ZERO, "refs/heads/#{branch}", 'commit', "user-#{user.id}", nil)
return true
end
def create_branch(new_ref, from_ref)
return false if new_ref.blank? || from_ref.blank? ||
repo.branches.none?{|b| b.name == from_ref} ||
repo.branches.one?{|b| b.name == new_ref}
restore_branch new_ref, from_ref
def create_branch(new_ref, from_ref, user)
branch = repo.branches.detect{|b| b.name == from_ref}
return false if !branch || repo.branches.one?{|b| b.name == new_ref}
restore_branch new_ref, branch.commit.id, user
end
def delete_branch(branch, user)