33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { execFile } from 'child_process' ;
76import * as nodePath from 'path' ;
8- import { promisify } from 'util' ;
97import { bulkhead } from 'cockatiel' ;
108import * as vscode from 'vscode' ;
119import { OctokitCommon } from './common' ;
@@ -62,6 +60,7 @@ import { EventType } from '../common/timelineEvent';
6260import { Schemes } from '../common/uri' ;
6361import { AsyncPredicate , batchPromiseAll , compareIgnoreCase , formatError , Predicate } from '../common/utils' ;
6462import { PULL_REQUEST_OVERVIEW_VIEW_TYPE } from '../common/webview' ;
63+ import { getWorktreeForBranch as envGetWorktreeForBranch , removeWorktree as envRemoveWorktree } from '../env/node/gitWorktree' ;
6564import { BRANCHES_ASSOCIATED_WITH_PRS , LAST_USED_EMAIL , NEVER_SHOW_PULL_NOTIFICATION , REPO_KEYS , ReposState } from '../extensionState' ;
6665import { git } from '../gitProviders/gitCommands' ;
6766import { IThemeWatcher } from '../themeWatcher' ;
@@ -2454,37 +2453,7 @@ export class FolderRepositoryManager extends Disposable {
24542453
24552454 async getWorktreeForBranch ( branchName : string ) : Promise < string | undefined > {
24562455 try {
2457- const execFileAsync = promisify ( execFile ) ;
2458- const gitPath = vscode . workspace . getConfiguration ( 'git' ) . get < string > ( 'path' ) || 'git' ;
2459- const { stdout } = await execFileAsync ( gitPath , [ 'worktree' , 'list' , '--porcelain' ] , {
2460- cwd : this . repository . rootUri . fsPath ,
2461- } ) ;
2462-
2463- const worktrees = stdout . split ( '\n\n' ) ;
2464- for ( const entry of worktrees ) {
2465- const lines = entry . trim ( ) . split ( '\n' ) ;
2466- let worktreePath : string | undefined ;
2467- let branch : string | undefined ;
2468- for ( const line of lines ) {
2469- if ( line . startsWith ( 'worktree ' ) ) {
2470- worktreePath = line . substring ( 'worktree ' . length ) ;
2471- } else if ( line . startsWith ( 'branch ' ) ) {
2472- branch = line . substring ( 'branch ' . length ) ;
2473- // branch line is like "branch refs/heads/branchName"
2474- const prefix = 'refs/heads/' ;
2475- if ( branch . startsWith ( prefix ) ) {
2476- branch = branch . substring ( prefix . length ) ;
2477- }
2478- }
2479- }
2480- if ( branch === branchName && worktreePath ) {
2481- // Don't return the main worktree (the repository root itself)
2482- const repoRoot = this . repository . rootUri . fsPath ;
2483- if ( nodePath . resolve ( worktreePath ) !== nodePath . resolve ( repoRoot ) ) {
2484- return worktreePath ;
2485- }
2486- }
2487- }
2456+ return await envGetWorktreeForBranch ( branchName , this . repository . rootUri . fsPath ) ;
24882457 } catch ( e ) {
24892458 Logger . error ( `Failed to get worktree for branch ${ branchName } : ${ e } ` , this . id ) ;
24902459 }
@@ -2493,11 +2462,7 @@ export class FolderRepositoryManager extends Disposable {
24932462
24942463 async removeWorktree ( worktreePath : string ) : Promise < void > {
24952464 try {
2496- const execFileAsync = promisify ( execFile ) ;
2497- const gitPath = vscode . workspace . getConfiguration ( 'git' ) . get < string > ( 'path' ) || 'git' ;
2498- await execFileAsync ( gitPath , [ 'worktree' , 'remove' , worktreePath ] , {
2499- cwd : this . repository . rootUri . fsPath ,
2500- } ) ;
2465+ await envRemoveWorktree ( worktreePath , this . repository . rootUri . fsPath ) ;
25012466 } catch ( e ) {
25022467 Logger . error ( `Failed to remove worktree ${ worktreePath } : ${ e } ` , this . id ) ;
25032468 throw e ;
0 commit comments