提交 961f4b5f 编写于 作者: M Mislav Marohnić

`pull-request` editor message defaults to single commit message

Closes #136
上级 990db02d
......@@ -125,7 +125,7 @@ module Hub
remote_branch = "#{head_project.remote}/#{options[:head]}"
options[:head] = "#{head_project.owner}:#{options[:head]}"
if !force and tracked_branch and local_commits = git_command("rev-list --cherry #{remote_branch}...")
if !force and tracked_branch and local_commits = rev_list(remote_branch, nil)
$stderr.puts "Aborted: #{local_commits.split("\n").size} commits are not yet pushed to #{remote_branch}"
warn "(use `-f` to force submit a pull request anyway)"
abort
......@@ -138,10 +138,25 @@ module Hub
unless options[:title] or options[:issue]
base_branch = "#{base_project.remote}/#{options[:base]}"
changes = git_command "log --no-color --pretty=medium --cherry %s...%s" %
[base_branch, remote_branch]
commits = rev_list(base_branch, remote_branch).to_s.split("\n")
case commits.size
when 0
default_message = commit_summary = nil
when 1
format = '%w(78,0,0)%s%n%+b'
default_message = git_command "show -s --format='#{format}' #{commits.first}"
commit_summary = nil
else
format = '%h (%aN, %ar)%n%w(78,3,3)%s%n%+b'
default_message = nil
commit_summary = git_command "log --no-color --format='%s' --cherry %s...%s" %
[format, base_branch, remote_branch]
end
options[:title], options[:body] = pullrequest_editmsg(changes) { |msg|
options[:title], options[:body] = pullrequest_editmsg(commit_summary) { |msg|
msg.puts default_message if default_message
msg.puts ""
msg.puts "# Requesting a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}"
msg.puts "#"
msg.puts "# Write a message for this pull request. The first block"
......@@ -898,7 +913,6 @@ help
def pullrequest_editmsg(changes)
message_file = File.join(git_dir, 'PULLREQ_EDITMSG')
File.open(message_file, 'w') { |msg|
msg.puts
yield msg
if changes
msg.puts "#\n# Changes:\n#"
......
......@@ -431,6 +431,10 @@ module Hub
git_config "alias.#{name}"
end
def rev_list(a, b)
git_command("rev-list --cherry-pick --right-only --no-merges #{a}...#{b}")
end
PWD = Dir.pwd
def current_dir
......
......@@ -816,7 +816,7 @@ class HubTest < Test::Unit::TestCase
def test_pullrequest_with_unpushed_commits
stub_tracking('master', 'mislav', 'master')
stub_command_output "rev-list --cherry mislav/master...", "+abcd1234\n+bcde2345"
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/master...", "+abcd1234\n+bcde2345"
expected = "Aborted: 2 commits are not yet pushed to mislav/master\n" <<
"(use `-f` to force submit a pull request anyway)\n"
......@@ -839,7 +839,7 @@ class HubTest < Test::Unit::TestCase
def test_pullrequest_from_tracking_branch
stub_branch('refs/heads/feature')
stub_tracking('feature', 'mislav', 'yay-feature')
stub_command_output "rev-list --cherry mislav/master...", nil
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/master...", nil
stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub").
with(:body => { 'pull' => {'base' => "master", 'head' => "mislav:yay-feature", 'title' => "hereyougo"} }).
......@@ -856,7 +856,7 @@ class HubTest < Test::Unit::TestCase
stub_github_token('789xyz', 'git.my.org')
stub_branch('refs/heads/feature')
stub_tracking_nothing('feature')
stub_command_output "rev-list --cherry origin/feature...", nil
stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil
stub_request(:post, "https://#{auth('myfiname', '789xyz')}git.my.org/api/v2/json/pulls/defunkt/hub").
with(:body => { 'pull' => {'base' => "master", 'head' => "myfiname:feature", 'title' => "hereyougo"} }).
......@@ -914,7 +914,7 @@ class HubTest < Test::Unit::TestCase
def test_pullrequest_existing_issue
stub_branch('refs/heads/myfix')
stub_tracking('myfix', 'mislav', 'awesomefix')
stub_command_output "rev-list --cherry mislav/awesomefix...", nil
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/awesomefix...", nil
stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub").
with(:body => { 'pull' => {'base' => "master", 'head' => "mislav:awesomefix", 'issue' => '92'} }).
......@@ -927,7 +927,7 @@ class HubTest < Test::Unit::TestCase
def test_pullrequest_existing_issue_url
stub_branch('refs/heads/myfix')
stub_tracking('myfix', 'mislav', 'awesomefix')
stub_command_output "rev-list --cherry mislav/awesomefix...", nil
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/awesomefix...", nil
stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/mojombo/hub").
with(:body => { 'pull' => {'base' => "master", 'head' => "mislav:awesomefix", 'issue' => '92'} }).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册