From c9b7f890fa6ea5e9b558eef633b211047ef7b90f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Jul 2013 17:29:41 +0400 Subject: [PATCH] #222: removed #restore_branch method --- .../projects/git/trees_controller.rb | 2 +- lib/modules/models/git.rb | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index b04a78688..e34fd8167 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -35,7 +35,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController end 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 end diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index 5770f30c4..032d8bb57 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -33,18 +33,15 @@ module Modules repo.tags.map(&:name) + repo.branches.map(&:name) 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) - 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 + return false if new_ref.blank? || from_ref.blank? || !(from_commit = repo.commit(from_ref)) + status, out, err = repo.git.native(:branch, {:process_info => true}, new_ref, from_commit.id) + 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 def delete_branch(branch, user)