提交 0a1b13eb 编写于 作者: M Mislav Marohnić

don't reuse outdated pull request messages

Prior to a53f0289, hub didn't clean up PULLREQ_EDITMSG files after a successful
pull request. When people upgrade to the new version of hub which reuses PR
messages, these leftover files will get reused when opening new PRs and will
lead to confusion. The hackish solution is to ignore PULLREQ_EDITMSG files that
are older than the hub ruby script on disk.
上级 11dd1207
...@@ -128,6 +128,26 @@ Feature: hub pull-request ...@@ -128,6 +128,26 @@ Feature: hub pull-request
When I successfully run `hub pull-request` When I successfully run `hub pull-request`
Then the file ".git/PULLREQ_EDITMSG" should not exist Then the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Ignore outdated PULLREQ_EDITMSG
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :title => "Added interactively", :body => nil
json :html_url => "https://github.com/mislav/coral/pull/12"
}
"""
And a file named ".git/PULLREQ_EDITMSG" with:
"""
Outdated message from old version of hub
"""
Given the file named ".git/PULLREQ_EDITMSG" is older than hub source
And the text editor adds:
"""
Added interactively
"""
When I successfully run `hub pull-request`
Then the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Text editor fails Scenario: Text editor fails
Given the text editor exits with error status Given the text editor exits with error status
And an empty file named ".git/PULLREQ_EDITMSG" And an empty file named ".git/PULLREQ_EDITMSG"
......
...@@ -143,6 +143,13 @@ Then /^the file "([^"]*)" should have mode "([^"]*)"$/ do |file, expected_mode| ...@@ -143,6 +143,13 @@ Then /^the file "([^"]*)" should have mode "([^"]*)"$/ do |file, expected_mode|
end end
end end
Given /^the file named "(.+?)" is older than hub source$/ do |file|
prep_for_fs_check do
time = File.mtime(File.expand_path('../../lib/hub/commands.rb', __FILE__)) - 60
File.utime(time, time, file)
end
end
Given /^the remote commit states of "(.*?)" "(.*?)" are:$/ do |proj, ref, json_value| Given /^the remote commit states of "(.*?)" "(.*?)" are:$/ do |proj, ref, json_value|
if ref == 'HEAD' if ref == 'HEAD'
empty_commit empty_commit
......
...@@ -1017,7 +1017,7 @@ help ...@@ -1017,7 +1017,7 @@ help
def pullrequest_editmsg(changes) def pullrequest_editmsg(changes)
message_file = pullrequest_editmsg_file message_file = pullrequest_editmsg_file
if File.exists?(message_file) if valid_editmsg_file?(message_file)
title, body = read_editmsg(message_file) title, body = read_editmsg(message_file)
previous_message = [title, body].compact.join("\n\n") if title previous_message = [title, body].compact.join("\n\n") if title
end end
...@@ -1046,6 +1046,14 @@ help ...@@ -1046,6 +1046,14 @@ help
[title, body] [title, body]
end end
# This unfortunate hack is because older versions of hub never cleaned up
# the pullrequest_editmsg_file, which newer hub would pick up and
# misinterpret as a message which should be reused after a failed PR.
def valid_editmsg_file?(message_file)
File.exists?(message_file) &&
File.mtime(message_file) > File.mtime(__FILE__)
end
def read_msg(message) def read_msg(message)
message.split("\n\n", 2).each {|s| s.strip! }.reject {|s| s.empty? } message.split("\n\n", 2).each {|s| s.strip! }.reject {|s| s.empty? }
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册