Add `hub merge` command #164

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
5 participants
Contributor

jfirebaugh commented Apr 17, 2012

It does what GitHub's "Merge pull request" button does:
merges the pull request with a nice commit message that
includes the pull request ID and title. Like hub checkout,
it creates a remote, but it does not create a local branch.

+1

Member

mislav commented Apr 23, 2012

Pretty solid. Makes sense to have an equivalent of GitHub's Merge Button™. I'll pull this in when I have a chance. Right now I'm working on the "api-v3" branch, which refactors a ton. When I'm done, I might ask you to rebase your changes. But give me some time first

Contributor

joliss commented May 1, 2012

Perhaps --no-ff would be reasonable here to mimic the Merge Button more closely. Having an explicit merge commit with the pull request # means

  • we keep a pointer to the discussion in the git history, and
  • GitHub will/should automatically close the pull request when you push.
diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb
index 289ec72..9a554cd 100644
--- a/lib/hub/commands.rb
+++ b/lib/hub/commands.rb
@@ -387,7 +387,7 @@ module Hub
         end
         idx = args.index url_arg
         args.delete_at idx
-        args.insert idx, "#{user}/#{branch}", '-m',
+        args.insert idx, "#{user}/#{branch}", '--no-ff', '-m',
                     "Merge pull request ##{pull_id} from #{user}/#{branch}\n\n#{pull_data['title']}"
       end
     end
Contributor

jfirebaugh commented May 1, 2012

Good call, done.

@jfirebaugh jfirebaugh Add `hub merge` command
It does what GitHub's "Merge pull request" button does:
merges the pull request with a nice commit message that
includes the pull request ID and title. Like `hub checkout`,
it creates a remote, but it does not create a local branch.
50c80d2
Contributor

jfirebaugh commented May 5, 2012

I've rebased this on master and updated it for the APIv3 changes.

Contributor

joliss commented May 5, 2012

If I merge repeatedly from the same repo, I get duplicate remote.*.fetch entries in .git/config:

[remote "jfirebaugh"]
    url = git://github.com/jfirebaugh/hub.git
    fetch = +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge
    fetch = +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge
    fetch = +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge
    fetch = +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge

I'm not sure if this happened before the rebase, only just noticed it.

Contributor

jfirebaugh commented May 6, 2012

This happens with hub checkout as well. Both commands run git remote set-branches --add <name> without checking if the fetch configuration for the remote already includes that branch, which it could do via an exact refspec like +refs/heads/hub_merge:refs/remotes/jfirebaugh/hub_merge or a pattern refspec such as the default +refs/heads/*:refs/remotes/jfirebaugh/*.

I couldn't find a way to script the check "does the remote fetch config include branch foo" other than parsing git remote show output, which seems overly brittle, or reimplementing refspec pattern matching, which seems overly complex.

Member

mislav commented May 7, 2012

@jfirebaugh Thanks, merged and improved in 77caa60...4719f39

@joliss Thanks for testing and feedback.

I've changed it to not create or update the remote. It simply fetches directly from the URL. I've also rewritten tests as cukes.

mislav closed this May 7, 2012

Contributor

joliss commented May 7, 2012

Oh this is very cool! Thanks Mislav!

Contributor

wking commented Dec 20, 2012

I was somewhat surprised to learn that hub merge doesn't use the merge-button api to merge pull requests. Instead, it creates the merge commit locally, but leaves the pull request open. Is there any change of using the GitHub API instead?

This issue has been closed for a while, so let me know if I should be bringing this up in a new issue.

Member

mislav commented Dec 20, 2012

@wking I'm surprised too. Maybe the button API didn't exist back then? Anyway, open a new issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment