Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Reuse PULLREQ_EDITMSG if creating pull request failed #325

Closed
wants to merge 2 commits into from

3 participants

@mmozuras

Do it by deleting PULLREQ_EDITMSG if everything's ok. Fixes #178

@mmozuras mmozuras Reuse PULLREQ_EDITMSG if creating pull request failed
Do it by deleting PULLREQ_EDITMSG if everything's ok. Fixes #178
d8e3228
@mislav
Owner

Nice start! But it seems like that the 2nd time you try a pull request, the PULLREQ_EDITMSG contents is used without the interactive step of opening the editor and allowing you to customize it.

Since hub pull-request opens an editor by default, I think it should do the same even if a previous message exists, just prefill it with previous message. Same as a failed git merge.

@badboy

Seems to work as expected now.

@mmozuras

Btw, do you want me to squash the commits?

@mislav
Owner

No need to squash. I'm improving this further, then pushing

@mislav
Owner

Improved in ea217d4...a53f028

Will release soon! Thanks

@mislav
Owner

Merged to master! a53f028

@mislav mislav closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 11, 2013
  1. @mmozuras

    Reuse PULLREQ_EDITMSG if creating pull request failed

    mmozuras authored
    Do it by deleting PULLREQ_EDITMSG if everything's ok. Fixes #178
  2. @mmozuras
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 8 deletions.
  1. +23 −8 lib/hub/commands.rb
View
31 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,19 +997,24 @@ def page_stdout
end
def pullrequest_editmsg(changes)
- message_file = File.join(git_dir, 'PULLREQ_EDITMSG')
- File.open(message_file, 'w') { |msg|
- yield msg
- if changes
- msg.puts "#\n# Changes:\n#"
- msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '')
- end
- }
+ message_file = pullreq_editmsg_file
+
+ unless File.exists?(message_file)
+ File.open(message_file, 'w') { |msg|
+ yield msg
+ if changes
+ msg.puts "#\n# Changes:\n#"
+ msg.puts changes.gsub(/^/, '# ').gsub(/ +$/, '')
+ end
+ }
+ end
+
edit_cmd = Array(git_editor).dup
edit_cmd << '-c' << 'set ft=gitcommit' if edit_cmd[0] =~ /^[mg]?vim$/
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 +1035,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
Something went wrong with that request. Please try again.