@@ -565,3 +565,45 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
565565 eq (t , strings .Join (ranCommands [2 ], " " ), "git config branch.feature.remote https://github.com/hubot/REPO.git" )
566566 eq (t , strings .Join (ranCommands [3 ], " " ), "git config branch.feature.merge refs/heads/feature" )
567567}
568+
569+ func TestPRCheckout_recurseSubmodules (t * testing.T ) {
570+ http := & httpmock.Registry {}
571+
572+ http .Register (httpmock .GraphQL (`query PullRequestByNumber\b` ), httpmock .StringResponse (`
573+ { "data": { "repository": { "pullRequest": {
574+ "number": 123,
575+ "headRefName": "feature",
576+ "headRepositoryOwner": {
577+ "login": "hubot"
578+ },
579+ "headRepository": {
580+ "name": "REPO"
581+ },
582+ "isCrossRepository": false,
583+ "maintainerCanModify": false
584+ } } } }
585+ ` ))
586+
587+ ranCommands := [][]string {}
588+ restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
589+ switch strings .Join (cmd .Args , " " ) {
590+ case "git show-ref --verify -- refs/heads/feature" :
591+ return & test.OutputStub {}
592+ default :
593+ ranCommands = append (ranCommands , cmd .Args )
594+ return & test.OutputStub {}
595+ }
596+ })
597+ defer restoreCmd ()
598+
599+ output , err := runCommand (http , nil , "master" , `123 --recurse-submodules` )
600+ eq (t , err , nil )
601+ eq (t , output .String (), "" )
602+
603+ eq (t , len (ranCommands ), 5 )
604+ eq (t , strings .Join (ranCommands [0 ], " " ), "git fetch origin +refs/heads/feature:refs/remotes/origin/feature" )
605+ eq (t , strings .Join (ranCommands [1 ], " " ), "git checkout feature" )
606+ eq (t , strings .Join (ranCommands [2 ], " " ), "git merge --ff-only refs/remotes/origin/feature" )
607+ eq (t , strings .Join (ranCommands [3 ], " " ), "git submodule sync --recursive" )
608+ eq (t , strings .Join (ranCommands [4 ], " " ), "git submodule update --init --recursive" )
609+ }
0 commit comments