@@ -147,7 +147,9 @@ interface OpenState {
147147interface CopyChangesState {
148148 subcommand : 'copy-changes' ;
149149 repo : string | Repository ;
150- worktree : GitWorktree ;
150+ /** Optional source worktree, defaults to the current worktree if not provided */
151+ source ?: GitWorktree ;
152+ target : GitWorktree ;
151153 changes :
152154 | { baseSha ?: string ; contents ?: string ; type : 'index' | 'working-tree' }
153155 | { baseSha : string ; contents : string ; type ?: 'index' | 'working-tree' } ;
@@ -228,7 +230,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
228230
229231 break ;
230232 case 'copy-changes' :
231- if ( args . state . worktree != null ) {
233+ if ( args . state . target != null ) {
232234 counter ++ ;
233235 }
234236
@@ -1153,39 +1155,46 @@ export class WorktreeGitCommand extends QuickCommand<State> {
11531155 while ( this . canStepsContinue ( state ) ) {
11541156 context . title = state ?. overrides ?. title ?? getTitle ( state . subcommand ) ;
11551157
1156- if ( state . counter < 3 || state . worktree == null ) {
1158+ if ( state . counter < 3 || state . target == null ) {
11571159 context . worktrees ??= ( await state . repo . git . worktrees ?. getWorktrees ( ) ) ?? [ ] ;
11581160
11591161 let placeholder ;
11601162 switch ( state . changes . type ) {
11611163 case 'index' :
1162- context . title = state ?. overrides ?. title ?? 'Copy Staged Changes to Worktree' ;
1163- placeholder = 'Choose a worktree to copy your staged changes to' ;
1164+ context . title =
1165+ state ?. overrides ?. title ??
1166+ `Copy Staged${ state . source ?. name ? ' Worktree' : '' } Changes to Worktree` ;
1167+ placeholder = `Choose a worktree to copy your staged${
1168+ state . source ?. name ? ' Worktree' : ''
1169+ } changes to`;
11641170 break ;
11651171 case 'working-tree' :
1166- context . title = state ?. overrides ?. title ?? 'Copy Working Changes to Worktree' ;
1167- placeholder = 'Choose a worktree to copy your working changes to' ;
1168- break ;
11691172 default :
1170- context . title = state ?. overrides ?. title ?? 'Copy Changes to Worktree' ;
1171- placeholder = 'Choose a worktree to copy changes to' ;
1173+ context . title =
1174+ state ?. overrides ?. title ??
1175+ `Copy Working${ state . source ?. name ? ' Worktree' : '' } Changes to Worktree` ;
1176+ placeholder = `Choose a worktree to copy your working${
1177+ state . source ?. name ? ' worktree' : ''
1178+ } changes to`;
11721179 break ;
11731180 }
11741181
11751182 const result = yield * pickWorktreeStep ( state , context , {
11761183 excludeOpened : true ,
11771184 includeStatus : true ,
1178- picked : state . worktree ?. uri ?. toString ( ) ,
1185+ picked : state . target ?. uri ?. toString ( ) ,
11791186 placeholder : placeholder ,
11801187 } ) ;
11811188 // Always break on the first step (so we will go back)
11821189 if ( result === StepResultBreak ) break ;
11831190
1184- state . worktree = result ;
1191+ state . target = result ;
11851192 }
11861193
1194+ const sourceSvc = this . container . git . getRepositoryService ( state . source ?. uri ?? state . repo . uri ) ;
1195+
11871196 if ( ! state . changes . contents || ! state . changes . baseSha ) {
1188- const diff = await state . repo . git . diff . getDiff ?.(
1197+ const diff = await sourceSvc . diff . getDiff ?.(
11891198 state . changes . type === 'index' ? uncommittedStaged : uncommitted ,
11901199 'HEAD' ,
11911200 {
@@ -1204,7 +1213,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
12041213 }
12051214
12061215 if ( ! isSha ( state . changes . baseSha ) ) {
1207- const sha = ( await state . repo . git . revision . resolveRevision ( state . changes . baseSha ) ) . sha ;
1216+ const sha = ( await sourceSvc . revision . resolveRevision ( state . changes . baseSha ) ) . sha ;
12081217 if ( sha != null ) {
12091218 state . changes . baseSha = sha ;
12101219 }
@@ -1218,15 +1227,15 @@ export class WorktreeGitCommand extends QuickCommand<State> {
12181227 endSteps ( state ) ;
12191228
12201229 try {
1221- const svc = this . container . git . getRepositoryService ( state . worktree . uri ) ;
1222- const commit = await svc . patch ?. createUnreachableCommitForPatch (
1230+ const commit = await sourceSvc . patch ?. createUnreachableCommitForPatch (
12231231 state . changes . baseSha ,
12241232 'Copied Changes' ,
12251233 state . changes . contents ,
12261234 ) ;
12271235 if ( commit == null ) return ;
12281236
1229- await svc . patch ?. applyUnreachableCommitForPatch ( commit . sha , { stash : false } ) ;
1237+ const targetSvc = this . container . git . getRepositoryService ( state . target . uri ) ;
1238+ await targetSvc . patch ?. applyUnreachableCommitForPatch ( commit . sha , { stash : false } ) ;
12301239 void window . showInformationMessage ( `Changes copied successfully` ) ;
12311240 } catch ( ex ) {
12321241 if ( ex instanceof CancellationError ) return ;
@@ -1253,7 +1262,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
12531262 {
12541263 subcommand : 'open' ,
12551264 repo : state . repo ,
1256- worktree : state . worktree ,
1265+ worktree : state . target ,
12571266 flags : [ ] ,
12581267 counter : 3 ,
12591268 confirm : true ,
@@ -1277,37 +1286,23 @@ export class WorktreeGitCommand extends QuickCommand<State> {
12771286 case 'index' :
12781287 confirmations . push ( {
12791288 label : 'Copy Staged Changes to Worktree' ,
1280- detail : `Will copy the staged changes${
1281- count > 0 ? ` ( ${ pluralize ( 'file' , count ) } ) ` : ''
1282- } to worktree '${ state . worktree . name } '`,
1289+ detail : `Will copy the staged changes${ count > 0 ? ` ( ${ pluralize ( 'file' , count ) } )` : '' } ${
1290+ state . source ? ` from worktree ' ${ state . source . name } ' ` : ''
1291+ } to worktree '${ state . target . name } '`,
12831292 } ) ;
12841293 break ;
12851294 case 'working-tree' :
1295+ default :
12861296 confirmations . push ( {
12871297 label : 'Copy Working Changes to Worktree' ,
1288- detail : `Will copy the working changes${
1289- count > 0 ? ` ( ${ pluralize ( 'file' , count ) } ) ` : ''
1290- } to worktree '${ state . worktree . name } '`,
1298+ detail : `Will copy the working changes${ count > 0 ? ` ( ${ pluralize ( 'file' , count ) } )` : '' } ${
1299+ state . source ? ` from worktree ' ${ state . source . name } ' ` : ''
1300+ } to worktree '${ state . target . name } '`,
12911301 } ) ;
12921302 break ;
1293-
1294- default :
1295- confirmations . push (
1296- createFlagsQuickPickItem ( [ ] , [ ] , {
1297- label : 'Copy Changes to Worktree' ,
1298- detail : `Will copy the changes${
1299- count > 0 ? ` (${ pluralize ( 'file' , count ) } )` : ''
1300- } to worktree '${ state . worktree . name } '`,
1301- } ) ,
1302- ) ;
1303- break ;
13041303 }
13051304
1306- const step = createConfirmStep (
1307- `Confirm ${ context . title } \u2022 ${ state . worktree . name } ` ,
1308- confirmations ,
1309- context ,
1310- ) ;
1305+ const step = createConfirmStep ( `Confirm ${ context . title } \u2022 ${ state . target . name } ` , confirmations , context ) ;
13111306
13121307 const selection : StepSelection < typeof step > = yield step ;
13131308 return canPickStepContinue ( step , state , selection ) ? undefined : StepResultBreak ;
0 commit comments