Cross repo pr create
Closes #354 

Currently we improperly specify the head ref when submitting a PR cross-repo. This PR fixes that.

Preview in browser and `-w` were and continue to be fine.

Most of the diff is testing.
given:

- a repo foo/foo
- a fork of the repo bar/foo
- remotes set up as `gh pr create` currently creates them when detecting a fork

submitting a PR prepared with `gh pr create` fails because the payload we pass to graphql isn't
specific enough:

```
failed to create pull request: graphql error: 'No commits between master and master'
```

`-w` and `Preview in browser` both work because we're appropriately signaling the fork in those
cases.

0.5.4

non-web PR creation fails for forks
diff --git a/command/pr_create.go b/command/pr_create.go
index 5a844d32431..7c1109b0916 100644
--- a/command/pr_create.go
+++ b/command/pr_create.go
@@ -176,12 +176,17 @@ func prCreate(cmd *cobra.Command, _ []string) error {
 			return fmt.Errorf("pull request title must not be blank")
 		}
 
+		headRefName := headBranch
+		if !ghrepo.IsSame(headRemote, baseRepo) {
+			headRefName = fmt.Sprintf("%s:%s", headRemote.RepoOwner(), headBranch)
+		}
+
 		params := map[string]interface{}{
 			"title":       title,
 			"body":        body,
 			"draft":       isDraft,
 			"baseRefName": baseBranch,
-			"headRefName": headBranch,
+			"headRefName": headRefName,
 		}
 
 		pr, err := api.CreatePullRequest(client, baseRepo, params)

diff --git a/command/pr_create_test.go b/command/pr_create_test.go
index 24d5bbd136a..72cbdce9459 100644
--- a/command/pr_create_test.go
+++ b/command/pr_create_test.go
@@ -10,6 +10,7 @@ import (
 	"strings"
 	"testing"
 
+	"github.com/cli/cli/context"
 	"github.com/cli/cli/git"
 	"github.com/cli/cli/test"
 	"github.com/cli/cli/utils"
@@ -131,3 +132,85 @@ Creating pull request for feature into master in OWNER/REPO
 
 `)
 }
+func TestPRCreate_cross_repo_same_branch(t *testing.T) {
+	ctx := context.NewBlank()
+	ctx.SetBranch("default")
+	ctx.SetRemotes(map[string]string{
+		"origin": "OWNER/REPO",
+		"fork":   "MYSELF/REPO",
+	})
+	initContext = func() context.Context {
+		return ctx
+	}
+	http := initFakeHTTP()
+	http.StubResponse(200, bytes.NewBufferString(`
+		{ "data": { "repo_000": {
+									"id": "REPOID0",
+									"name": "REPO",
+									"owner": {"login": "OWNER"},
+									"defaultBranchRef": {
+										"name": "default",
+										"target": {"oid": "deadbeef"}
+									},
+									"viewerPermission": "READ"
+								},
+								"repo_001" : {
+									"parent": {
+										"id": "REPOID0",
+										"name": "REPO",
+										"owner": {"login": "OWNER"},
+										"defaultBranchRef": {
+											"name": "default",
+											"target": {"oid": "deadbeef"}
+										},
+										"viewerPermission": "READ"
+									},
+									"id": "REPOID1",
+									"name": "REPO",
+									"owner": {"login": "MYSELF"},
+									"defaultBranchRef": {
+										"name": "default",
+										"target": {"oid": "deadbeef"}
+									},
+									"viewerPermission": "WRITE"
+		} } }
+	`))
+	http.StubResponse(200, bytes.NewBufferString(`
+		{ "data": { "createPullRequest": { "pullRequest": {
+			"URL": "https://github.com/OWNER/REPO/pull/12"
+		} } } }
+	`))
+
+	origGitCommand := git.GitCommand
+	git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "clean")
+	defer func() {
+		git.GitCommand = origGitCommand
+	}()
+
+	output, err := RunCommand(prCreateCmd, `pr create -t "cross repo" -b "same branch"`)
+	eq(t, err, nil)
+
+	bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
+	reqBody := struct {
+		Variables struct {
+			Input struct {
+				RepositoryID string
+				Title        string
+				Body         string
+				BaseRefName  string
+				HeadRefName  string
+			}
+		}
+	}{}
+	json.Unmarshal(bodyBytes, &reqBody)
+
+	eq(t, reqBody.Variables.Input.RepositoryID, "REPOID0")
+	eq(t, reqBody.Variables.Input.Title, "cross repo")
+	eq(t, reqBody.Variables.Input.Body, "same branch")
+	eq(t, reqBody.Variables.Input.BaseRefName, "default")
+	eq(t, reqBody.Variables.Input.HeadRefName, "MYSELF:default")
+
+	eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
+
+	// goal: only care that gql is formatted properly
+}

{"TestPRCreate_cross_repo_same_branch": {"run": "NONE", "test": "FAIL", "fix": "PASS"}}
{"TestExtractName/Incomplete_front-matter": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPullRequest_ChecksStatus": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueView_preview": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_urlArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCompletion_fish": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_branchArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_differentRepo_existingBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestReplaceExcessiveWhitespace": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_sshParse": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCheckForUpdate/current_is_prerelease": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind/Multiple_templates": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestGitStatusHelperProcess": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRStatus_reviewsAndChecks": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestChangelogURL": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueStatus_disabledIssues": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueCreate": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCheckForUpdate": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueView": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestGraphQLError": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_previewCurrentBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind/Empty_multiple_templates_directory": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractName": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestGraphQL": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRStatus_blankSlate": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestForOS/Windows": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_branchWithOwnerArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFuzzyAgo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCompletion_bash": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractName/No_front-matter": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRList": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_printError/Cobra_flag_error": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCompletion_zsh": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestForOS": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_differentRepo_remoteExists": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCreate_ReportsUncommittedChanges": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractName/Complete_front-matter": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_urlArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_UncommittedChangeCount": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueView_urlArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_printError/DNS_error": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueStatus": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind/Template_in_docs": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueCreate_web": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractContents": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_existingBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind/Template_in_.github_takes_precedence": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_printError/generic_error": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueCreate_disabledIssues": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestFind/Template_in_root": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCompletion_unsupported": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_sameRepo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCreate": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueList_disabledIssues": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_Translator": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRList_filteringAssignee": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRList_filteringAssigneeLabels": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_currentBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueList_withFlags": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractContents/Has_front-matter": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestExtractContents/No_front-matter": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_differentRepo_currentBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCheckForUpdate/latest_is_older": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_preview": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueList": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_maintainerCanModify": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueView_disabledIssues": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCheckForUpdate/latest_is_current": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_numberArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRView_noResultsForBranch": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_printError": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCreate_web": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRStatus": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_printError/unknown_Cobra_command_error": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPrCreateHelperProcess": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestForOS/macOS": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestForOS/Linux": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_branchArg": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_repoFromURL": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_parseRemotes": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRCheckout_differentRepo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueView_notFound": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestPRList_filtering": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueStatus_blankSlate": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestIssueList_nullAssigneeLabels": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "TestCheckForUpdate/latest_is_newer": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "Test_repoFromURL_invalid": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"TestPRCreate_cross_repo_same_branch": {"run": "NONE", "test": "FAIL", "fix": "PASS"}}
{"passed_count": 87, "failed_count": 1, "skipped_count": 0, "passed_tests": ["TestExtractName/Incomplete_front-matter", "TestPullRequest_ChecksStatus", "TestPRView_urlArg", "TestCompletion_fish", "TestPRView_branchArg", "TestReplaceExcessiveWhitespace", "TestFind/Multiple_templates", "TestFind", "TestPRStatus_reviewsAndChecks", "TestChangelogURL", "TestCheckForUpdate", "TestPRView_previewCurrentBranch", "TestGraphQL", "TestPRStatus_blankSlate", "TestPRView_branchWithOwnerArg", "TestCompletion_bash", "TestExtractName/No_front-matter", "Test_printError/Cobra_flag_error", "TestCompletion_zsh", "TestForOS", "Test_UncommittedChangeCount", "Test_printError/DNS_error", "TestIssueStatus", "TestFind/Template_in_docs", "TestExtractContents", "TestFind/Template_in_.github_takes_precedence", "Test_printError/generic_error", "TestPRCheckout_sameRepo", "TestIssueList_disabledIssues", "TestPRList_filteringAssigneeLabels", "TestPRView_currentBranch", "TestIssueList_withFlags", "TestExtractContents/Has_front-matter", "TestPRView_preview", "TestIssueView_disabledIssues", "TestCheckForUpdate/latest_is_current", "TestPRCreate_web", "TestPRCheckout_branchArg", "TestPRCheckout_differentRepo", "TestPRList_filtering", "Test_repoFromURL_invalid", "TestIssueView_preview", "TestPRCheckout_differentRepo_existingBranch", "Test_sshParse", "TestCheckForUpdate/current_is_prerelease", "TestGitStatusHelperProcess", "TestIssueStatus_disabledIssues", "TestIssueCreate", "TestIssueView", "TestGraphQLError", "TestFind/Empty_multiple_templates_directory", "TestExtractName", "TestForOS/Windows", "TestFuzzyAgo", "TestPRList", "TestPRCheckout_differentRepo_remoteExists", "TestPRCreate_ReportsUncommittedChanges", "TestExtractName/Complete_front-matter", "TestPRCheckout_urlArg", "TestIssueView_urlArg", "TestIssueCreate_web", "TestPRCheckout_existingBranch", "TestIssueCreate_disabledIssues", "TestFind/Template_in_root", "TestCompletion_unsupported", "TestPRCreate", "Test_Translator", "TestPRList_filteringAssignee", "TestExtractContents/No_front-matter", "TestPRCheckout_differentRepo_currentBranch", "TestCheckForUpdate/latest_is_older", "TestIssueList", "TestPRCheckout_maintainerCanModify", "TestPRView_numberArg", "TestPRView_noResultsForBranch", "Test_printError", "TestPRStatus", "Test_printError/unknown_Cobra_command_error", "TestPrCreateHelperProcess", "TestForOS/macOS", "TestForOS/Linux", "Test_repoFromURL", "Test_parseRemotes", "TestIssueView_notFound", "TestIssueStatus_blankSlate", "TestIssueList_nullAssigneeLabels", "TestCheckForUpdate/latest_is_newer"], "failed_tests": ["github.com/cli/cli/context"], "skipped_tests": []}
{"passed_count": 87, "failed_count": 3, "skipped_count": 0, "passed_tests": ["TestExtractName/Incomplete_front-matter", "TestPullRequest_ChecksStatus", "TestPRView_urlArg", "TestCompletion_fish", "TestPRView_branchArg", "TestReplaceExcessiveWhitespace", "TestFind/Multiple_templates", "TestFind", "TestPRStatus_reviewsAndChecks", "TestChangelogURL", "TestCheckForUpdate", "TestPRView_previewCurrentBranch", "TestGraphQL", "TestPRStatus_blankSlate", "TestPRView_branchWithOwnerArg", "TestCompletion_bash", "TestExtractName/No_front-matter", "Test_printError/Cobra_flag_error", "TestCompletion_zsh", "TestForOS", "Test_UncommittedChangeCount", "Test_printError/DNS_error", "TestIssueStatus", "TestFind/Template_in_docs", "TestExtractContents", "TestFind/Template_in_.github_takes_precedence", "Test_printError/generic_error", "TestPRCheckout_sameRepo", "TestIssueList_disabledIssues", "TestPRList_filteringAssigneeLabels", "TestPRView_currentBranch", "TestIssueList_withFlags", "TestExtractContents/Has_front-matter", "TestPRView_preview", "TestIssueView_disabledIssues", "TestCheckForUpdate/latest_is_current", "TestPRCreate_web", "TestPRCheckout_branchArg", "TestPRCheckout_differentRepo", "TestPRList_filtering", "Test_repoFromURL_invalid", "TestIssueView_preview", "TestPRCheckout_differentRepo_existingBranch", "Test_sshParse", "TestCheckForUpdate/current_is_prerelease", "TestGitStatusHelperProcess", "TestIssueStatus_disabledIssues", "TestIssueCreate", "TestIssueView", "TestGraphQLError", "TestFind/Empty_multiple_templates_directory", "TestExtractName", "TestForOS/Windows", "TestFuzzyAgo", "TestPRList", "TestPRCheckout_differentRepo_remoteExists", "TestPRCreate_ReportsUncommittedChanges", "TestExtractName/Complete_front-matter", "TestPRCheckout_urlArg", "TestIssueView_urlArg", "TestIssueCreate_web", "TestPRCheckout_existingBranch", "TestIssueCreate_disabledIssues", "TestFind/Template_in_root", "TestCompletion_unsupported", "TestPRCreate", "Test_Translator", "TestPRList_filteringAssignee", "TestExtractContents/No_front-matter", "TestPRCheckout_differentRepo_currentBranch", "TestCheckForUpdate/latest_is_older", "TestIssueList", "TestPRCheckout_maintainerCanModify", "TestPRView_numberArg", "TestPRView_noResultsForBranch", "Test_printError", "TestPRStatus", "Test_printError/unknown_Cobra_command_error", "TestPrCreateHelperProcess", "TestForOS/macOS", "TestForOS/Linux", "Test_repoFromURL", "Test_parseRemotes", "TestIssueView_notFound", "TestIssueStatus_blankSlate", "TestIssueList_nullAssigneeLabels", "TestCheckForUpdate/latest_is_newer"], "failed_tests": ["github.com/cli/cli/context", "github.com/cli/cli/command", "TestPRCreate_cross_repo_same_branch"], "skipped_tests": []}
{"passed_count": 88, "failed_count": 1, "skipped_count": 0, "passed_tests": ["TestExtractName/Incomplete_front-matter", "TestPullRequest_ChecksStatus", "TestPRView_urlArg", "TestCompletion_fish", "TestPRView_branchArg", "TestReplaceExcessiveWhitespace", "TestFind/Multiple_templates", "TestFind", "TestPRStatus_reviewsAndChecks", "TestChangelogURL", "TestCheckForUpdate", "TestPRView_previewCurrentBranch", "TestGraphQL", "TestPRStatus_blankSlate", "TestPRView_branchWithOwnerArg", "TestCompletion_bash", "TestExtractName/No_front-matter", "Test_printError/Cobra_flag_error", "TestCompletion_zsh", "TestForOS", "Test_UncommittedChangeCount", "Test_printError/DNS_error", "TestIssueStatus", "TestFind/Template_in_docs", "TestExtractContents", "TestFind/Template_in_.github_takes_precedence", "Test_printError/generic_error", "TestPRCheckout_sameRepo", "TestIssueList_disabledIssues", "TestPRList_filteringAssigneeLabels", "TestPRView_currentBranch", "TestIssueList_withFlags", "TestExtractContents/Has_front-matter", "TestPRView_preview", "TestIssueView_disabledIssues", "TestCheckForUpdate/latest_is_current", "TestPRCreate_web", "TestPRCheckout_branchArg", "TestPRCheckout_differentRepo", "TestPRList_filtering", "Test_repoFromURL_invalid", "TestIssueView_preview", "TestPRCheckout_differentRepo_existingBranch", "Test_sshParse", "TestCheckForUpdate/current_is_prerelease", "TestGitStatusHelperProcess", "TestIssueStatus_disabledIssues", "TestIssueCreate", "TestIssueView", "TestGraphQLError", "TestFind/Empty_multiple_templates_directory", "TestExtractName", "TestForOS/Windows", "TestFuzzyAgo", "TestPRList", "TestPRCheckout_differentRepo_remoteExists", "TestPRCreate_ReportsUncommittedChanges", "TestExtractName/Complete_front-matter", "TestPRCheckout_urlArg", "TestIssueView_urlArg", "TestIssueCreate_web", "TestPRCheckout_existingBranch", "TestIssueCreate_disabledIssues", "TestFind/Template_in_root", "TestCompletion_unsupported", "TestPRCreate", "Test_Translator", "TestPRList_filteringAssignee", "TestExtractContents/No_front-matter", "TestPRCheckout_differentRepo_currentBranch", "TestCheckForUpdate/latest_is_older", "TestIssueList", "TestPRCheckout_maintainerCanModify", "TestPRView_numberArg", "TestPRView_noResultsForBranch", "Test_printError", "TestPRStatus", "Test_printError/unknown_Cobra_command_error", "TestPrCreateHelperProcess", "TestForOS/macOS", "TestForOS/Linux", "Test_repoFromURL", "TestPRCreate_cross_repo_same_branch", "Test_parseRemotes", "TestIssueView_notFound", "TestIssueStatus_blankSlate", "TestIssueList_nullAssigneeLabels", "TestCheckForUpdate/latest_is_newer"], "failed_tests": ["github.com/cli/cli/context"], "skipped_tests": []}