@@ -2,7 +2,7 @@ import { EntityIdentifierUtils } from '@gitkraken/provider-apis/entity-identifie
22import type { TextEditor } from 'vscode' ;
33import { env , Uri , window , workspace } from 'vscode' ;
44import type { ScmResource } from '../@types/vscode.git.resources' ;
5- import { ScmResourceGroupType } from '../@types/vscode.git.resources.enums' ;
5+ import { ScmResourceGroupType , ScmStatus } from '../@types/vscode.git.resources.enums' ;
66import type { GlCommands } from '../constants.commands' ;
77import { GlCommand } from '../constants.commands' ;
88import type { IntegrationId } from '../constants.integrations' ;
@@ -22,6 +22,7 @@ import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
2222import { command } from '../system/-webview/command' ;
2323import { map } from '../system/iterable' ;
2424import { Logger } from '../system/logger' ;
25+ import { isViewRefFileNode } from '../views/nodes/utils/-webview/node.utils' ;
2526import type { Change , CreateDraft } from '../webviews/plus/patchDetails/protocol' ;
2627import { ActiveEditorCommand , GlCommandBase } from './commandBase' ;
2728import type { CommandContext } from './commandContext' ;
@@ -38,6 +39,8 @@ export interface CreatePatchCommandArgs {
3839 repoPath ?: string ;
3940 uris ?: Uri [ ] ;
4041
42+ includeUntracked ?: boolean ;
43+
4144 title ?: string ;
4245 description ?: string ;
4346}
@@ -56,10 +59,13 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
5659 const resourcesByGroup = new Map < ScmResourceGroupType , ScmResource [ ] > ( ) ;
5760 const uris = new Set < string > ( ) ;
5861
62+ let includeUntracked = false ;
63+
5964 let repo ;
6065 for ( const resource of context . scmResourceStates as ScmResource [ ] ) {
6166 repo ??= await this . container . git . getOrOpenRepository ( resource . resourceUri ) ;
6267
68+ includeUntracked = includeUntracked || resource . type === ScmStatus . UNTRACKED ;
6369 uris . add ( resource . resourceUri . toString ( ) ) ;
6470
6571 let groupResources = resourcesByGroup . get ( resource . resourceGroupType ! ) ;
@@ -81,6 +87,7 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
8187 from : 'HEAD' ,
8288 uris : [ ...map ( uris , u => Uri . parse ( u ) ) ] ,
8389 title : to === uncommittedStaged ? 'Staged Changes' : 'Uncommitted Changes' ,
90+ includeUntracked : includeUntracked ? true : undefined ,
8491 } ;
8592 } else if ( context . type === 'scm-groups' ) {
8693 const group = context . scmResourceGroups [ 0 ] ;
@@ -131,6 +138,22 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
131138 uris : [ context . node . uri ] ,
132139 } ;
133140 }
141+ } else if ( context . type === 'viewItems' ) {
142+ if ( isViewRefFileNode ( context . node ) ) {
143+ args = {
144+ repoPath : context . node . repoPath ,
145+ to : context . node . ref . sha ,
146+ from : `${ context . node . ref . sha } ^` ,
147+ uris : [ context . node . uri ] ,
148+ title : `Changes (partial) in ${ shortenRevision ( context . node . ref . sha ) } ` ,
149+ } ;
150+
151+ for ( const node of context . nodes ) {
152+ if ( isViewRefFileNode ( node ) && node !== context . node && node . ref . sha === args . to ) {
153+ args . uris ! . push ( node . uri ) ;
154+ }
155+ }
156+ }
134157 }
135158 }
136159
@@ -147,13 +170,10 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
147170
148171 return repo . git
149172 . diff ( )
150- . getDiff ?.(
151- args ?. to ?? uncommitted ,
152- args ?. from ?? 'HEAD' ,
153- args ?. uris ?. length
154- ? { uris : args . uris }
155- : { includeUntracked : args ?. to != null || args ?. to === uncommitted } ,
156- ) ;
173+ . getDiff ?.( args ?. to ?? uncommitted , args ?. from ?? 'HEAD' , {
174+ includeUntracked : args ?. includeUntracked ?? ( args ?. to != null || args ?. to === uncommitted ) ,
175+ uris : args ?. uris ,
176+ } ) ;
157177 }
158178
159179 abstract override execute ( args ?: CreatePatchCommandArgs ) : Promise < void > ;
0 commit comments