@@ -448,6 +448,46 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
448448 eq (t , strings .Join (ranCommands [1 ], " " ), "git checkout feature" )
449449}
450450
451+ func TestPRCheckout_detachedHead (t * testing.T ) {
452+ http := & httpmock.Registry {}
453+ defer http .Verify (t )
454+
455+ http .Register (httpmock .GraphQL (`query PullRequestByNumber\b` ), httpmock .StringResponse (`
456+ { "data": { "repository": { "pullRequest": {
457+ "number": 123,
458+ "headRefName": "feature",
459+ "headRepositoryOwner": {
460+ "login": "hubot"
461+ },
462+ "headRepository": {
463+ "name": "REPO"
464+ },
465+ "isCrossRepository": true,
466+ "maintainerCanModify": true
467+ } } } }
468+ ` ))
469+
470+ ranCommands := [][]string {}
471+ restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
472+ switch strings .Join (cmd .Args , " " ) {
473+ case "git config branch.feature.merge" :
474+ return & test.OutputStub {Out : []byte ("refs/heads/feature\n " )}
475+ default :
476+ ranCommands = append (ranCommands , cmd .Args )
477+ return & test.OutputStub {}
478+ }
479+ })
480+ defer restoreCmd ()
481+
482+ output , err := runCommand (http , nil , "" , `123` )
483+ eq (t , err , nil )
484+ eq (t , output .String (), "" )
485+
486+ eq (t , len (ranCommands ), 2 )
487+ eq (t , strings .Join (ranCommands [0 ], " " ), "git fetch origin refs/pull/123/head:feature" )
488+ eq (t , strings .Join (ranCommands [1 ], " " ), "git checkout feature" )
489+ }
490+
451491func TestPRCheckout_differentRepo_currentBranch (t * testing.T ) {
452492 http := & httpmock.Registry {}
453493 defer http .Verify (t )
0 commit comments