@@ -383,11 +383,20 @@ export async function getWorkspaceConfiguration(cliHost: CLIHost, workspace: Wor
383383 }
384384 let { workspaceFolder, workspaceMount } = config ;
385385 let additionalMountString : string | undefined ;
386- if ( workspace && ( ! workspaceFolder || ! ( 'workspaceMount' in config ) ) ) {
386+ if ( workspace && ( ! workspaceFolder || ! ( 'workspaceMount' in config ) || ( mountWorkspaceGitRoot && mountGitWorktreeCommonDir ) ) ) {
387387 const hostMountFolder = await getHostMountFolder ( cliHost , workspace . rootFolderPath , mountWorkspaceGitRoot , output ) ;
388388
389+ // When the user provides a custom workspaceMount, derive containerMountFolder from its
390+ // target= value so that the worktree common-dir path is computed correctly.
391+ let containerMountFolder : string ;
392+ if ( 'workspaceMount' in config && config . workspaceMount ) {
393+ const targetMatch = / (?: ^ | , ) (?: d s t | d e s t i n a t i o n | t a r g e t ) = (?: " ( [ ^ " ] + ) " | ( [ ^ , ] + ) ) / . exec ( config . workspaceMount ) ;
394+ containerMountFolder = targetMatch ? ( targetMatch [ 1 ] ?? targetMatch [ 2 ] ) : path . posix . join ( '/workspaces' , cliHost . path . basename ( hostMountFolder ) ) ;
395+ } else {
396+ containerMountFolder = path . posix . join ( '/workspaces' , cliHost . path . basename ( hostMountFolder ) ) ;
397+ }
398+
389399 // Check if .git is a file (worktree) with a relative gitdir path
390- let containerMountFolder = path . posix . join ( '/workspaces' , cliHost . path . basename ( hostMountFolder ) ) ;
391400 if ( mountWorkspaceGitRoot && mountGitWorktreeCommonDir ) {
392401 const dotGitPath = cliHost . path . join ( hostMountFolder , '.git' ) ;
393402 if ( await cliHost . isFile ( dotGitPath ) ) {
@@ -399,12 +408,16 @@ export async function getWorkspaceConfiguration(cliHost: CLIHost, workspace: Wor
399408 if ( ! cliHost . path . isAbsolute ( gitdir ) ) {
400409 // gitdir points to .git/worktrees/<name>/, common dir is .git/ (two levels up)
401410 const gitCommonDir = cliHost . path . resolve ( hostMountFolder , gitdir , '..' , '..' ) ;
402- // Collect path segments from hostMountFolder up to the parent of gitCommonDir
403- const segments : string [ ] = [ ] ;
404- for ( let current = hostMountFolder ; ! gitCommonDir . startsWith ( current + cliHost . path . sep ) && current !== cliHost . path . dirname ( current ) ; current = cliHost . path . dirname ( current ) ) {
405- segments . unshift ( cliHost . path . basename ( current ) ) ;
411+ // Only recompute containerMountFolder when the workspace mount is auto-generated;
412+ // when the user supplied workspaceMount, keep the target they specified.
413+ if ( ! ( 'workspaceMount' in config ) ) {
414+ // Collect path segments from hostMountFolder up to the parent of gitCommonDir
415+ const segments : string [ ] = [ ] ;
416+ for ( let current = hostMountFolder ; ! gitCommonDir . startsWith ( current + cliHost . path . sep ) && current !== cliHost . path . dirname ( current ) ; current = cliHost . path . dirname ( current ) ) {
417+ segments . unshift ( cliHost . path . basename ( current ) ) ;
418+ }
419+ containerMountFolder = path . posix . join ( '/workspaces' , ...segments ) ;
406420 }
407- containerMountFolder = path . posix . join ( '/workspaces' , ...segments ) ;
408421 // Calculate where the common dir should be mounted in the container
409422 const containerGitdir = cliHost . platform === 'win32' ? gitdir . replace ( / \\ / g, '/' ) : gitdir ;
410423 const containerGitCommonDir = path . posix . resolve ( containerMountFolder , containerGitdir , '..' , '..' ) ;
0 commit comments