vermiculus / magithub

**DEPRECATED - please use Forge instead!** -- Magit-based interfaces to GitHub
GNU General Public License v3.0
579 stars 63 forks source link

Cannot open new pull requests H p #358

Open se7entyse7en opened 6 years ago

se7entyse7en commented 6 years ago

Hi, first of all thanks for this awesome project! I was using magithub on mac and everything was working flawlessly. Now at work I'm using it on ubuntu and for some reason I cannot open new pull requests (using H p) as it always complains: Nothing on remote yet; have you pushed your branch? Aborting. Is this due to a misconfiguration?

vermiculus commented 6 years ago

I'm assuming you did push the branch before trying to open the PR? Assuming you still have the branch around (or a branch that can reproduce this issue; feel free to use vermiculus/my-new-repository as a testing ground), can you provide your .git/config?

se7entyse7en commented 6 years ago

Hi @vermiculus, sorry for late reply, it was happening for every branch, and yes I the branch was pushed on origin. Anyway here's my .git/config:

[core]
    repositoryformatversion = 0
    filemode = true
        bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:a-user/a-project.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "develop"]
    remote = origin
    merge = refs/heads/develop
[branch "a-branch"]
    remote = origin
    merge = refs/heads/a-branch
[branch "master"]
    remote = origin
    merge = refs/heads/master

I solved it by adding:

[remote]
    pushDefault = origin
vermiculus commented 6 years ago

Ah, yes; this is working as designed, though I am a little confused: does magit know to push a-branch to origin? I thought when you pushed a branch, it sets pushDefault.

If that's not the case, I can add an (or …) for using branch.remote if branch.pushDefault isn't defined.

se7entyse7en commented 6 years ago

Honestly I don't know git at this low level, but no it doesn't seem to set pushDefault on a per-branch basis even after the first push. May it depend on the git version? If you could add the fallback to branch.remote it would be awesome.

vermiculus commented 6 years ago

I'm not sure. @tarsius, do you have any wisdom on how pushDefault is set? Is this a git thing or a magit thing?

tarsius commented 6 years ago

Git respects that variable but never sets it. A few Magit commands offer to set it unless configured otherwise.

vermiculus commented 6 years ago

I'm trying to get the upstream remote. Would I be correct in saying that branch.pushDefault should be preferred, but branch.remote could be a fallback?

Edit

More specifically I'm trying to get the remote tracking branch.

tarsius commented 6 years ago

I am not sure what you are asking for, so I have to be quite explicit.

In order to open a pull request you have to tell github about two branches: the source branch and the target branch. Obviously both of these branches have to be located inside a github remote (possibly but not necessarily the same one), because github doesn't have access to the repository on your own machine.

I assume that the first thing that you ask the user is "What branch would you like to be merged?" and that you default to the current branch.

But again, this has to be a branch on a github remote, so you have to determine the remote branch that corresponds to the selected local branch (*), not actually the current branch. To determine that branch you should use (format "%s/%s" (magit-get-push-remote) (magit-current-branch), provided magit-get-push-remote doesn't return nil obviously. If the user selects another local branch, then use (format "%s/%s" (magit-get-push-remote branch) branch).

Lets assume that's non-nil. Now you have to determine the branch into which that is supposed to be merged. magit-get-upstream-branch may return a local or a remote branch, depending on what the user prefers. If it is a local branch, then do something similar to what magit-get-indirect-upstream-branch does to get the corresponding remote branch.

If the push remote for the selected source branch is not set, then you have to resort to heuristics (e.g. if only one REMOTE/foo exists for foo, then use that). You can definitely not use the upstream branch, because then you would end up asking to merge e.g. origin/master into origin/master itself.

All of this works well if the user has embraced The Two Remotes. Otherwise it won't. (I am planning to implement forge-create-pullreq over the weekend or so, and while I am not sure yet about it I will probably insist on a properly configured triangular workflow and else fall back to asking the user to provide everything explicitly without attempting to guess any defaults. I recommend you do that too.)

() Of course you could also ask for a remote branch instead. But that might actually complicate matters because now you have to determine the local* branch that corresponds to that remote branch before you can use the upstream of that local branch as the (default) target.