dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

Don't use hub's `-e` option

Open gabebw opened this issue 6 years ago • 1 comments

There's an interesting bug where it tries to be helpful and ends up being not so helpful.

First, some background.

My git-create-pull-request script builds up a long markdown file in a tempfile and then passes it to hub using this command:

hub pull-request -e -o -F 'PATH_TO_TEMPFILE'

hub then reads PATH_TO_TEMPFILE, copies it into .git/PULLREQ_EDITMSG, and opens .git/PULLREQ_EDITMSG for further editing.

If the pull request is successfully created, then .git/PULLREQ_EDITMSG is deleted.

If the PR is not successfully created, .git/PULLREQ_EDITMSG is kept as-is. And here's where the problem comes in.

If you then run hub pull-request -e -o -F 'PATH_TO_TEMPFILE' again after the PR creation fails, hub will not change the contents of PULLREQ_EDITMSG. The old commit message will stick around.

That leads to this interesting bug:

  • Successfully a PR for branch A.
  • Get up and have some tea.
  • Now that you're back at your computer, try to create the PR for branch A. It fails, saying there's already a PR for branch A.
  • Move on to branch B and try to create a PR for branch B.
  • The message that pops up in your editor is the leftover message for branch A, not the message that git-create-pull-request generated for branch B.

(You can replicate this by running this:

  • echo good > message
  • echo bad > .git/PULLREQ_EDITMSG
  • hub pull-request -e -o -F message.
  • Your editor will show bad, not good. )

I think I'll have to revert https://github.com/gabebw/dotfiles/pull/128.

gabebw avatar Jun 24 '18 04:06 gabebw

I could also add rm .git/PULLREQ_EDITMSG inside this if statement:

https://github.com/gabebw/dotfiles/blob/3d99c5ab326f766c7b7218d86c7ba60210d63ed0/bin/git-create-pull-request#L306-L311

gabebw avatar Jun 05 '19 06:06 gabebw

Fixed in https://github.com/gabebw/dotfiles/commit/202a64ed73f01da240d8c7a32c7ca9703bcb3ef5, I believe.

gabebw avatar Sep 30 '22 20:09 gabebw