Respect git "core.commentchar" setting

The comment char is read from git config if it exists, but defaults to
"#" as before.

Fixes #530
This commit is contained in:
Mislav Marohnić 2014-05-18 12:46:41 +07:00
Родитель e806603b6d
Коммит 1570fec324
3 изменённых файлов: 40 добавлений и 12 удалений

Просмотреть файл

@ -155,6 +155,27 @@ Feature: hub pull-request
Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
And the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Text editor with custom commentchar
Given git "core.commentchar" is set to "/"
And the text editor adds:
"""
# Dat title
/ This line is commented out.
Dem body.
"""
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :title => '# Dat title',
:body => 'Dem body.'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request`
Then the output should contain exactly "the://url\n"
Scenario: Failed pull request preserves previous message
Given the text editor adds:
"""

Просмотреть файл

@ -232,14 +232,14 @@ module Hub
[format, base_branch, remote_branch]
end
options[:title], options[:body] = pullrequest_editmsg(commit_summary) { |msg, initial_message|
options[:title], options[:body] = pullrequest_editmsg(commit_summary) { |msg, initial_message, cc|
initial_message ||= default_message
msg.puts initial_message if initial_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"
msg.puts "# of text is the title and the rest is description."
msg.puts "#{cc} Requesting a pull to #{base_project.owner}:#{options[:base]} from #{options[:head]}"
msg.puts "#{cc}"
msg.puts "#{cc} Write a message for this pull request. The first block"
msg.puts "#{cc} of text is the title and the rest is description."
}
end
@ -1072,17 +1072,18 @@ help
def pullrequest_editmsg(changes)
message_file = pullrequest_editmsg_file
cc = git_commentchar
if valid_editmsg_file?(message_file)
title, body = read_editmsg(message_file)
title, body = read_editmsg(message_file, cc)
previous_message = [title, body].compact.join("\n\n") if title
end
File.open(message_file, 'w') { |msg|
yield msg, previous_message
yield msg, previous_message, cc
if changes
msg.puts "#\n# Changes:\n#"
msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '')
msg.puts "#{cc}\n#{cc} Changes:\n#{cc}"
msg.puts changes.gsub(/^/, "#{cc} ").gsub(/ +$/, '')
end
}
@ -1097,7 +1098,7 @@ help
abort "error using text editor for pull request message"
end
title, body = read_editmsg(message_file)
title, body = read_editmsg(message_file, cc)
abort "Aborting due to empty pull request title" unless title
[title, body]
end
@ -1118,11 +1119,11 @@ help
File.join(git_dir, 'PULLREQ_EDITMSG')
end
def read_editmsg(file)
def read_editmsg(file, commentchar)
title, body = '', ''
File.open(file, 'r') { |msg|
msg.each_line do |line|
next if line.index('#') == 0
next if line.index(commentchar) == 0
((title.empty? and line =~ /\S/) ? title : body) << line
end
}

Просмотреть файл

@ -504,6 +504,12 @@ module Hub
end
end
def git_commentchar
if str = git_config('core.commentchar') then str[0,1]
else '#'
end
end
module System
# Cross-platform web browser command; respects the value set in $BROWSER.
#