@@ -9,10 +9,12 @@ import (
99 "strings"
1010 "testing"
1111
12+ "github.com/MakeNowJust/heredoc"
1213 "github.com/cli/cli/context"
1314 "github.com/cli/cli/git"
1415 "github.com/cli/cli/internal/config"
1516 "github.com/cli/cli/internal/ghrepo"
17+ "github.com/cli/cli/internal/run"
1618 "github.com/cli/cli/pkg/cmdutil"
1719 "github.com/cli/cli/pkg/httpmock"
1820 "github.com/cli/cli/pkg/iostreams"
@@ -288,6 +290,70 @@ func TestPRCreate_createFork(t *testing.T) {
288290 assert .Equal (t , "https://github.com/OWNER/REPO/pull/12\n " , output .String ())
289291}
290292
293+ func TestPRCreate_pushToNonBaseRepo (t * testing.T ) {
294+ remotes := context.Remotes {
295+ {
296+ Remote : & git.Remote {
297+ Name : "upstream" ,
298+ Resolved : "base" ,
299+ },
300+ Repo : ghrepo .New ("OWNER" , "REPO" ),
301+ },
302+ {
303+ Remote : & git.Remote {
304+ Name : "origin" ,
305+ Resolved : "base" ,
306+ },
307+ Repo : ghrepo .New ("monalisa" , "REPO" ),
308+ },
309+ }
310+
311+ http := initFakeHTTP ()
312+ defer http .Verify (t )
313+
314+ http .StubRepoInfoResponse ("OWNER" , "REPO" , "master" )
315+ http .Register (
316+ httpmock .GraphQL (`query PullRequestForBranch\b` ),
317+ httpmock .StringResponse (`
318+ { "data": { "repository": { "pullRequests": { "nodes" : [
319+ ] } } } }
320+ ` ))
321+ http .Register (
322+ httpmock .GraphQL (`mutation PullRequestCreate\b` ),
323+ httpmock .GraphQLMutation (`
324+ { "data": { "createPullRequest": { "pullRequest": {
325+ "URL": "https://github.com/OWNER/REPO/pull/12"
326+ } } } }
327+ ` , func (input map [string ]interface {}) {
328+ assert .Equal (t , "REPOID" , input ["repositoryId" ].(string ))
329+ assert .Equal (t , "master" , input ["baseRefName" ].(string ))
330+ assert .Equal (t , "monalisa:feature" , input ["headRefName" ].(string ))
331+ }))
332+
333+ cs , cmdTeardown := run .Stub ()
334+ defer cmdTeardown (t )
335+
336+ cs .Register ("git status" , 0 , "" )
337+ cs .Register (`git config --get-regexp \^branch\\\.feature\\\.` , 1 , "" ) // determineTrackingBranch
338+ cs .Register ("git show-ref --verify" , 0 , heredoc .Doc (`
339+ deadbeef HEAD
340+ deadb00f refs/remotes/upstream/feature
341+ deadbeef refs/remotes/origin/feature
342+ ` )) // determineTrackingBranch
343+ cs .Register ("git .+ log" , 1 , "" , func (args []string ) {
344+ assert .Equal (t , "upstream/master...feature" , args [len (args )- 1 ])
345+ })
346+
347+ _ , cleanupAsk := prompt .InitAskStubber ()
348+ defer cleanupAsk ()
349+
350+ output , err := runCommand (http , remotes , "feature" , true , `-t title -b body` )
351+ require .NoError (t , err )
352+
353+ assert .Equal (t , "\n Creating pull request for monalisa:feature into master in OWNER/REPO\n \n " , output .Stderr ())
354+ assert .Equal (t , "https://github.com/OWNER/REPO/pull/12\n " , output .String ())
355+ }
356+
291357func TestPRCreate_nonLegacyTemplate (t * testing.T ) {
292358 http := initFakeHTTP ()
293359 defer http .Verify (t )
0 commit comments