@@ -30,18 +30,19 @@ describe('PullRequestManager', function () {
3030 let manager : FolderRepositoryManager ;
3131 let telemetry : MockTelemetry ;
3232 let mockThemeWatcher : MockThemeWatcher ;
33+ let mockRepository : MockRepository ;
3334
3435 beforeEach ( function ( ) {
3536 sinon = createSandbox ( ) ;
3637 MockCommandRegistry . install ( sinon ) ;
3738
3839 telemetry = new MockTelemetry ( ) ;
3940 mockThemeWatcher = new MockThemeWatcher ( ) ;
40- const repository = new MockRepository ( ) ;
41+ mockRepository = new MockRepository ( ) ;
4142 const context = new MockExtensionContext ( ) ;
4243 const credentialStore = new CredentialStore ( telemetry , context ) ;
4344 const repositoriesManager = new RepositoriesManager ( credentialStore , telemetry ) ;
44- manager = new FolderRepositoryManager ( 0 , context , repository , telemetry , new GitApiImpl ( repositoriesManager ) , credentialStore , new CreatePullRequestHelper ( ) , mockThemeWatcher ) ;
45+ manager = new FolderRepositoryManager ( 0 , context , mockRepository , telemetry , new GitApiImpl ( repositoriesManager ) , credentialStore , new CreatePullRequestHelper ( ) , mockThemeWatcher ) ;
4546 } ) ;
4647
4748 afterEach ( function ( ) {
@@ -68,6 +69,38 @@ describe('PullRequestManager', function () {
6869 assert . deepStrictEqual ( manager . activePullRequest , pr ) ;
6970 } ) ;
7071 } ) ;
72+
73+ describe ( 'getOrigin' , function ( ) {
74+ it ( 'falls back to configured GitHub remote when upstream is not GitHub' , async function ( ) {
75+ // Setup: Add a GitHub remote
76+ const githubUrl = 'https://github.com/test/repo.git' ;
77+ await mockRepository . addRemote ( 'github' , githubUrl ) ;
78+
79+ const githubProtocol = new Protocol ( githubUrl ) ;
80+ const githubRemote = new GitHubRemote ( 'github' , githubUrl , githubProtocol , GitHubServerType . GitHubDotCom ) ;
81+ const rootUri = Uri . file ( '/test/repo' ) ;
82+ const githubRepository = new GitHubRepository ( 1 , githubRemote , rootUri , manager . credentialStore , telemetry ) ;
83+
84+ // Manually set up the GitHub repository in the manager (simulating successful initialization)
85+ ( manager as any ) . _githubRepositories = [ githubRepository ] ;
86+
87+ // Add a non-GitHub remote (simulating the scenario from the bug)
88+ await mockRepository . addRemote ( 'origin' , 'https://example.com/git/repo.git' ) ;
89+
90+ // Create a branch with upstream set to non-GitHub remote
91+ await mockRepository . createBranch ( 'test-branch' , true ) ;
92+ await mockRepository . setBranchUpstream ( 'test-branch' , 'refs/remotes/origin/main' ) ;
93+
94+ // Mock getAllGitHubRemotes to return only the github remote
95+ sinon . stub ( manager , 'getAllGitHubRemotes' ) . resolves ( [ githubRemote ] ) ;
96+
97+ // Act: getOrigin should fall back to the configured GitHub remote instead of throwing
98+ const result = await manager . getOrigin ( ) ;
99+
100+ // Assert: Should return the GitHub repository, not throw an error
101+ assert . strictEqual ( result , githubRepository ) ;
102+ } ) ;
103+ } ) ;
71104} ) ;
72105
73106describe ( 'titleAndBodyFrom' , function ( ) {
0 commit comments