@@ -12,6 +12,7 @@ import {
1212 extractRepositoryName ,
1313 getWorkspaceGitInfo ,
1414 GitRepositoryInfo ,
15+ convertGitUrlToHttps ,
1516} from "../git"
1617import { truncateOutput } from "../../integrations/misc/extract-text"
1718
@@ -560,6 +561,89 @@ describe("getGitRepositoryInfo", () => {
560561 repositoryName : "RooCodeInc/Roo-Code" ,
561562 } )
562563 } )
564+
565+ it ( "should convert SSH URLs to HTTPS format" , async ( ) => {
566+ // Clear previous mocks
567+ vitest . clearAllMocks ( )
568+
569+ // Create a spy to track the implementation
570+ const gitSpy = vitest . spyOn ( fs . promises , "readFile" )
571+
572+ // Mock successful access to .git directory
573+ vitest . mocked ( fs . promises . access ) . mockResolvedValue ( undefined )
574+
575+ // Mock git config file with SSH URL
576+ const mockConfig = `
577+ [core]
578+ repositoryformatversion = 0
579+ filemode = true
580+ bare = false
581+ [remote "origin"]
582+ url = [email protected] :RooCodeInc/Roo-Code.git 583+ fetch = +refs/heads/*:refs/remotes/origin/*
584+ [branch "main"]
585+ remote = origin
586+ merge = refs/heads/main
587+ `
588+ // Mock HEAD file content
589+ const mockHead = "ref: refs/heads/main"
590+
591+ // Setup the readFile mock to return different values based on the path
592+ gitSpy . mockImplementation ( ( path : any , encoding : any ) => {
593+ if ( path === configPath ) {
594+ return Promise . resolve ( mockConfig )
595+ } else if ( path === headPath ) {
596+ return Promise . resolve ( mockHead )
597+ }
598+ return Promise . reject ( new Error ( `Unexpected path: ${ path } ` ) )
599+ } )
600+
601+ const result = await getGitRepositoryInfo ( workspaceRoot )
602+
603+ // Verify that the SSH URL was converted to HTTPS
604+ expect ( result ) . toEqual ( {
605+ repositoryUrl : "https://github.com/RooCodeInc/Roo-Code.git" ,
606+ repositoryName : "RooCodeInc/Roo-Code" ,
607+ defaultBranch : "main" ,
608+ } )
609+ } )
610+ } )
611+
612+ describe ( "convertGitUrlToHttps" , ( ) => {
613+ it ( "should leave HTTPS URLs unchanged" , ( ) => {
614+ const url = "https://github.com/RooCodeInc/Roo-Code.git"
615+ const converted = convertGitUrlToHttps ( url )
616+
617+ expect ( converted ) . toBe ( "https://github.com/RooCodeInc/Roo-Code.git" )
618+ } )
619+
620+ it ( "should convert SSH URLs to HTTPS format" , ( ) => {
621+ const url = "[email protected] :RooCodeInc/Roo-Code.git" 622+ const converted = convertGitUrlToHttps ( url )
623+
624+ expect ( converted ) . toBe ( "https://github.com/RooCodeInc/Roo-Code.git" )
625+ } )
626+
627+ it ( "should convert SSH URLs with ssh:// prefix to HTTPS format" , ( ) => {
628+ const url = "ssh://[email protected] /RooCodeInc/Roo-Code.git" 629+ const converted = convertGitUrlToHttps ( url )
630+
631+ expect ( converted ) . toBe ( "https://github.com/RooCodeInc/Roo-Code.git" )
632+ } )
633+
634+ it ( "should handle URLs without git@ prefix" , ( ) => {
635+ const url = "ssh://github.com/RooCodeInc/Roo-Code.git"
636+ const converted = convertGitUrlToHttps ( url )
637+
638+ expect ( converted ) . toBe ( "https://github.com/RooCodeInc/Roo-Code.git" )
639+ } )
640+
641+ it ( "should handle invalid URLs gracefully" , ( ) => {
642+ const url = "not-a-valid-url"
643+ const converted = convertGitUrlToHttps ( url )
644+
645+ expect ( converted ) . toBe ( "not-a-valid-url" )
646+ } )
563647} )
564648
565649describe ( "sanitizeGitUrl" , ( ) => {
0 commit comments