@@ -1449,57 +1449,20 @@ export class GitVCS {
14491449 }
14501450 }
14511451
1452- async discardChanges (
1453- changes : { path : string ; status : [ git . HeadStatus , git . WorkdirStatus , git . StageStatus ] } [ ] ,
1454- options ?: { discardStaged ?: boolean ; discardUnstaged ?: boolean } ,
1455- ) {
1452+ async discardChanges ( changes : { path : string ; status : [ git . HeadStatus , git . WorkdirStatus , git . StageStatus ] } [ ] ) {
14561453 for ( const change of changes ) {
1457- // If the file didn't exist in HEAD, remove it
1454+ // If the file didn't exist in HEAD, we need to remove it
14581455 if ( change . status [ 0 ] === 0 ) {
14591456 await git . remove ( { ...this . _baseOpts , filepath : change . path } ) ;
14601457 // @ts -expect-error -- TSCONVERSION
14611458 await this . _baseOpts . fs . promises . unlink ( change . path ) ;
14621459 } else {
1463- // Discard staged changes only
1464- if ( options ?. discardStaged ) {
1465- await git . resetIndex ( { ...this . _baseOpts , filepath : change . path } ) ;
1466- }
1467-
1468- // Discard unstaged changes only.
1469- if ( options ?. discardUnstaged ) {
1470- // Restore workdir from index (staged version)
1471- // 1. Get staged blob OID
1472- const statusMatrix = await git . statusMatrix ( { ...this . _baseOpts } ) ;
1473- const row = statusMatrix . find ( ( [ filepath ] ) => filepath === change . path ) ;
1474- if ( row ) {
1475- const [ , , , stageStatusCode ] = row ;
1476- if ( stageStatusCode !== 0 ) {
1477- // 2. Get staged blob content
1478- const index = await git . listFiles ( { ...this . _baseOpts } ) ;
1479- if ( index . includes ( change . path ) ) {
1480- // Use fileStatus logic to get staged content:
1481- const { stage } = await this . fileStatus ( change . path ) ;
1482- if ( stage !== null ) {
1483- // 3. Write staged content to workdir
1484- // @ts -expect-error -- TSCONVERSION
1485- await this . _baseOpts . fs . promises . writeFile ( change . path , stage , 'utf8' ) ;
1486- }
1487- }
1488- }
1489- }
1490- // Do NOT touch the index (staged changes are preserved)
1491- continue ;
1492- }
1493-
1494- // Default: discard both (current behavior)
1495- if ( ! options ?. discardStaged && ! options ?. discardUnstaged ) {
1496- await git . checkout ( {
1497- ...this . _baseOpts ,
1498- force : true ,
1499- ref : await this . getCurrentBranch ( ) ,
1500- filepaths : [ convertToPosixSep ( change . path ) ] ,
1501- } ) ;
1502- }
1460+ await git . checkout ( {
1461+ ...this . _baseOpts ,
1462+ force : true ,
1463+ ref : await this . getCurrentBranch ( ) ,
1464+ filepaths : [ convertToPosixSep ( change . path ) ] ,
1465+ } ) ;
15031466 }
15041467 }
15051468 }
0 commit comments