Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reuse PULLREQ_EDITMSG if creating pull request failed

Do it by deleting PULLREQ_EDITMSG if everything's ok. Fixes #178
  • Loading branch information...
commit d8e3228497559e446a9c832ab0bd6b25e1003af1 1 parent daa0352
@mmozuras authored
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/hub/commands.rb
View
19 lib/hub/commands.rb
@@ -218,6 +218,8 @@ def pull_request(args)
pull = api_client.create_pullrequest(options)
+ delete_pullreq_editmsg_file
+
args.executable = 'echo'
args.replace [pull['html_url']]
rescue GitHubAPI::Exceptions
@@ -995,7 +997,13 @@ def page_stdout
end
def pullrequest_editmsg(changes)
- message_file = File.join(git_dir, 'PULLREQ_EDITMSG')
+ message_file = pullreq_editmsg_file
+
+ if File.exists?(message_file)
+ title, body = read_editmsg(message_file)
+ return [title, body] unless title
+ end
+
File.open(message_file, 'w') { |msg|
yield msg
if changes
@@ -1008,6 +1016,7 @@ def pullrequest_editmsg(changes)
edit_cmd << message_file
system(*edit_cmd)
abort "can't open text editor for pull request message" unless $?.success?
+
title, body = read_editmsg(message_file)
abort "Aborting due to empty pull request title" unless title
[title, body]
@@ -1028,6 +1037,14 @@ def read_editmsg(file)
[title =~ /\S/ ? title : nil, body =~ /\S/ ? body : nil]
end
+ def delete_pullreq_editmsg_file
+ File.delete(pullreq_editmsg_file) if File.exists?(pullreq_editmsg_file)
+ end
+
+ def pullreq_editmsg_file
+ File.join(git_dir, 'PULLREQ_EDITMSG')
+ end
+
def expand_alias(cmd)
if expanded = git_alias_for(cmd)
if expanded.index('!') != 0
Please sign in to comment.
Something went wrong with that request. Please try again.