diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb
index 4bf4d16fb..58a8f0658 100644
--- a/app/controllers/projects/pull_requests_controller.rb
+++ b/app/controllers/projects/pull_requests_controller.rb
@@ -10,7 +10,6 @@ class Projects::PullRequestsController < Projects::BaseController
def new
@pull = PullRequest.default_base_project(@project).pull_requests.new
- FileUtils.rm_rf @pull.path
#@pull.build_issue
@pull.issue = @project.issues.new
@pull.head_project = @project
diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb
index 54e840c9b..a4a274f26 100644
--- a/app/models/pull_request.rb
+++ b/app/models/pull_request.rb
@@ -8,7 +8,10 @@ class PullRequest < ActiveRecord::Base
delegate :user, :title, :body, :serial_id, :assignee, :state, :to => :issue, :allow_nil => true
accepts_nested_attributes_for :issue
#attr_accessible #FIXME disable for development
- scope :needed_checking, where(:state => ['open', 'blocked', 'ready'])
+ #validate :uniq_merge
+ before_create :clean_dir
+
+ scope :needed_checking, includes(:issue).where(:issues => {:state => ['open', 'blocked', 'ready', 'already']})
state_machine :initial => :open do
#after_transition [:ready, :blocked] => [:merged, :closed] do |pull, transition|
@@ -79,19 +82,6 @@ class PullRequest < ActiveRecord::Base
project.is_root? ? project : project.root
end
- def clean #FIXME move to protected
- Dir.chdir(path) do
- base_project.branches.each {|branch| system 'git', 'checkout', branch.name}
- system 'git', 'checkout', base_ref
-
- base_project.branches.each do |branch|
- system 'git', 'branch', '-D', branch.name unless [base_ref, head_branch].include? branch.name
- end
- base_project.tags.each do |tag|
- system 'git', 'tag', '-d', tag.name unless [base_ref, head_branch].include? tag.name
- end
- end
- end
def path
filename = [id, base_ref, head_project.owner.uname, head_project.name, head_ref].compact.join('-')
@@ -143,4 +133,28 @@ class PullRequest < ActiveRecord::Base
end
# TODO catch errors
end
+
+ def clean
+ Dir.chdir(path) do
+ base_project.branches.each {|branch| system 'git', 'checkout', branch.name}
+ system 'git', 'checkout', base_ref
+
+ base_project.branches.each do |branch|
+ system 'git', 'branch', '-D', branch.name unless [base_ref, head_branch].include? branch.name
+ end
+ base_project.tags.each do |tag|
+ system 'git', 'tag', '-d', tag.name unless [base_ref, head_branch].include? tag.name
+ end
+ end
+ end
+
+ def uniq_merge
+ if base_project.pull_requests.needed_checking.where('pull_requests.id != ?', id).count >= 1
+ errors.add(:head_ref, t('projects.pull_requests.duplicate', :head_ref => head_ref))
+ end
+ end
+
+ def clean_dir
+ FileUtils.rm_rf path
+ end
end
diff --git a/app/views/projects/pull_requests/new.html.haml b/app/views/projects/pull_requests/new.html.haml
index 8edb4df2d..c23bc4130 100644
--- a/app/views/projects/pull_requests/new.html.haml
+++ b/app/views/projects/pull_requests/new.html.haml
@@ -33,6 +33,11 @@
.leftlist=issue.label :title, t('activerecord.attributes.issue.body'), :class => :label
.rightlist=issue.text_area :body
.both
+
+ .leftlist for debug
+ .rightlist=@pull.state
+ .both
+
.leftlist
\
.rightlist=f.submit t('.submit'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :id => 'create_pull'
diff --git a/config/locales/models/pull_request.en.yml b/config/locales/models/pull_request.en.yml
index f7111c923..d1e83e9ba 100644
--- a/config/locales/models/pull_request.en.yml
+++ b/config/locales/models/pull_request.en.yml
@@ -3,13 +3,14 @@ en:
pull_requests:
new:
new: 'Create a pull request into %{base} from %{head}'
- base_ref: 'Base'
- head_ref: 'Head'
+ base_ref: Base
+ head_ref: Head
refs: 'branch · tag · commit'
- base_project: 'Base project'
- head_project: 'Head project'
- submit: 'Send pull request'
+ base_project: Base project
+ head_project: Head project
+ submit: Send pull request
merge: Merge
+ duplicate: There's already a pull request for %{head_ref}
pull_requests:
tabs:
diff --git a/config/locales/models/pull_request.ru.yml b/config/locales/models/pull_request.ru.yml
index 03ce62f52..7524dddfa 100644
--- a/config/locales/models/pull_request.ru.yml
+++ b/config/locales/models/pull_request.ru.yml
@@ -3,13 +3,14 @@ ru:
pull_requests:
new:
new: 'Создать запрос на слияние в %{base} из %{head}'
- base_ref: 'База'
- head_ref: 'Источник'
+ base_ref: База
+ head_ref: Источник
refs: 'branch · tag · commit'
- base_project: 'Базовый проект'
- head_project: 'Проект-источник'
- submit: 'Создать запрос на слияние'
+ base_project: Базовый проект
+ head_project: Проект-источник
+ submit: Создать запрос на слияние
merge: Слияние
+ duplicate: Уже существует запрос на слияние %{head_ref}
pull_requests:
tabs:
diff --git a/spec/models/pull_request_spec.rb b/spec/models/pull_request_spec.rb
index d6ca0e383..883b7ae0d 100644
--- a/spec/models/pull_request_spec.rb
+++ b/spec/models/pull_request_spec.rb
@@ -23,7 +23,7 @@ describe PullRequest do
context 'for owner user' do
before (:all) do
- stub_rsync_methods
+ stub_symlink_methods
@user = FactoryGirl.create(:user)
set_data_for_pull
@pull = @project.pull_requests.new(:issue_attributes => {:title => 'test', :body => 'testing'})
@@ -74,10 +74,20 @@ describe PullRequest do
@other_pull.state.should == 'already'
end
end
+
+ it "should not be created same pull" do
+ @same_pull = @project.pull_requests.new(:issue_attributes => {:title => 'same', :body => 'testing'})
+ @same_pull.issue.user, @same_pull.issue.project = @user, @same_pull.base_project
+ @same_pull.base_ref = 'master'
+ @same_pull.head_project, @same_pull.head_ref = @project, 'non_conflicts'
+ @same_pull.save
+ @project.pull_requests.includes(:issue).where(:issues => {:title => @same_pull.title}).count.should == 0
+ end
+
end
before(:all) do
- stub_rsync_methods
+ stub_symlink_methods
Platform.delete_all
User.delete_all
Repository.delete_all