diff --git a/app/models/project.rb b/app/models/project.rb index 6b9e87277..bbccd9552 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -294,9 +294,12 @@ class Project < ActiveRecord::Base self.name = new_name FileUtils.mv old_path, new_path, :force => true - FileUtils.mv File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, old_name), - File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, new_name), - :force => true + pull_requests_old_path = File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, old_name) + if Dir.exists?(pull_requests_old_path) + FileUtils.mv pull_requests_old_path, + File.join(APP_CONFIG['git_path'], 'pull_requests', owner.uname, new_name), + :force => true + end PullRequest.where(:from_project_id => id).update_all(:from_project_name => new_name) diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ee0a6e514..b67b8bbbc 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -49,13 +49,13 @@ class PullRequest < ActiveRecord::Base end end - def update_relations(old_from_project_name) + def update_relations(old_from_project_name = nil) FileUtils.mv path(old_from_project_name), path, :force => true if old_from_project_name return unless Dir.exists?(path) Dir.chdir(path) do system 'git', 'remote', 'remove', 'origin' system 'git', 'remote', 'add', 'origin', to_project.path - if to_project != from_project + if cross_pull? system 'git', 'remote', 'remove', 'head' system 'git', 'remote', 'add', 'head', from_project.path end @@ -123,11 +123,7 @@ class PullRequest < ActiveRecord::Base end def from_branch - if to_project_id != from_project_id - "head_#{from_ref}" - else - from_ref - end + cross_pull? ? "head_#{from_ref}" : from_ref end def common_ancestor @@ -196,7 +192,7 @@ class PullRequest < ActiveRecord::Base `rm -rf #{path}` git.fs_mkdir('..') git.clone(options, to_project.path, path) - if to_project != from_project + if cross_pull? Dir.chdir(path) do system 'git', 'remote', 'add', 'head', from_project.path end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e2075067b..e2aea9421 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -94,9 +94,7 @@ describe Project do it 'ensures that path to git repository has been changed after rename of project' do project = FactoryGirl.create(:project_with_commit) - project.name = "#{project.name}_renamed" - project.save - project.reload + project.update_attributes(:name => "#{project.name}-new") Dir.exists?(project.path).should be_true end diff --git a/spec/models/pull_request_spec.rb b/spec/models/pull_request_spec.rb index ab1de8796..692c08515 100644 --- a/spec/models/pull_request_spec.rb +++ b/spec/models/pull_request_spec.rb @@ -33,6 +33,13 @@ describe PullRequest do @other_pull.save end + it 'ensures that path to pull_request repository has been changed after rename of project' do + @pull.check + @project.update_attributes(:name => "#{@project.name}-new") + @pull.reload + Dir.exists?(@pull.path).should be_true + end + it 'master should merge with non_conflicts branch' do @pull.check @pull.status.should == 'ready'