Merge pull request #864 from warpc/719-tag_pull

[refs #719] fix errors with tags && rewriting history
This commit is contained in:
Vladimir Sharshov 2013-01-28 10:51:56 -08:00
commit 610e2dc1d0
2 changed files with 31 additions and 8 deletions

View File

@ -48,6 +48,11 @@ class PullRequest < ActiveRecord::Base
end end
def check(do_transaction = true) def check(do_transaction = true)
if do_transaction && !valid?
issue.set_close nil
issue.save(:validate => false) # FIXME remove this hack
return false
end
res = merge res = merge
new_status = case res new_status = case res
when /Already up-to-date/ when /Already up-to-date/
@ -171,16 +176,18 @@ class PullRequest < ActiveRecord::Base
end end
Dir.chdir(path) do Dir.chdir(path) do
system 'git', 'checkout', to_ref system 'git', 'tag', '-d', from_ref, to_ref
system 'git', 'pull', 'origin', to_ref system 'git fetch --tags'
if to_project_id == from_project_id tags, head = repo.tags.map(&:name), to_project == from_project ? 'origin' : 'head'
system 'git', 'checkout', from_ref unless tags.include? to_ref
system 'git', 'pull', 'origin', from_ref system 'git', 'checkout', to_ref
else system 'git', 'reset', '--hard', "origin/#{to_ref}"
system 'git', 'fetch', 'head', "+#{from_ref}:#{from_branch}" end
unless tags.include? from_ref
system 'git', 'branch', '-D', from_branch
system 'git', 'fetch', head, "+#{from_ref}:#{from_branch}"
end end
end end
# TODO catch errors
end end
def clean def clean

View File

@ -96,6 +96,22 @@ describe PullRequest do
@wrong_pull.save @wrong_pull.save
@project.pull_requests.joins(:issue).where(:issues => {:title => @wrong_pull.title}).count.should == 0 @project.pull_requests.joins(:issue).where(:issues => {:title => @wrong_pull.title}).count.should == 0
end end
it "should create pull with tag" do
system("cd #{@project.path} && git tag 4.7.5.3 $(git rev-parse #{@pull.from_ref})") # TODO REDO through grit
@pull = @project.pull_requests.new(:issue_attributes => {:title => 'tag', :body => 'testing'})
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
@pull.to_ref = 'master'
@pull.from_project, @pull.from_ref = @project, '4.7.5.3'
@pull.save
@project.pull_requests.joins(:issue).where(:issues => {:title => @pull.title}).count.should == 1
end
it "should close pull when deleting from branch" do
system("cd #{@project.path} && git branch -D #{@pull.from_branch}")
@pull.check
@project.pull_requests.joins(:issue).where(:issues => {:title => @pull.title, :status => 'closed'}).count.should == 1
end
end end
before do before do