#222: removed #restore_branch method

This commit is contained in:
Vokhmin Alexey V 2013-07-23 17:29:41 +04:00
parent f69013329a
commit c9b7f890fa
2 changed files with 9 additions and 12 deletions

View File

@ -35,7 +35,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end end
def restore_branch def restore_branch
status = @project.restore_branch(@treeish, params[:sha], current_user) ? 200 : 422 status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422
render :nothing => true, :status => status render :nothing => true, :status => status
end end

View File

@ -33,18 +33,15 @@ module Modules
repo.tags.map(&:name) + repo.branches.map(&:name) repo.tags.map(&:name) + repo.branches.map(&:name)
end end
# TODO: return something else instead of empty string on success and error
def restore_branch(branch, sha, user)
return false if branch.blank? || sha.blank? || repo.commit(sha).nil?
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, user) def create_branch(new_ref, from_ref, user)
branch = repo.branches.detect{|b| b.name == from_ref} return false if new_ref.blank? || from_ref.blank? || !(from_commit = repo.commit(from_ref))
return false if !branch || repo.branches.one?{|b| b.name == new_ref} status, out, err = repo.git.native(:branch, {:process_info => true}, new_ref, from_commit.id)
restore_branch new_ref, branch.commit.id, user if status == 0
Resque.enqueue(GitHook, owner.uname, name, from_commit.id, GitHook::ZERO, "refs/heads/#{new_ref}", 'commit', "user-#{user.id}", nil)
return true
end
return false
end end
def delete_branch(branch, user) def delete_branch(branch, user)