@@ -1552,32 +1552,25 @@ private async void OnStageChunk(object _1, RoutedEventArgs _2)
15521552
15531553 using var lockWatcher = repo . LockWatcher ( ) ;
15541554
1555- if ( ! selection . HasLeftChanges )
1555+ var tmpFile = Path . GetTempFileName ( ) ;
1556+ if ( change . WorkTree == Models . ChangeState . Untracked )
15561557 {
1557- await new Commands . Add ( repo . FullPath , change ) . ExecAsync ( ) ;
1558+ diff . GenerateNewPatchFromSelection ( change , null , selection , false , tmpFile ) ;
1559+ }
1560+ else if ( chunk . Combined )
1561+ {
1562+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1563+ diff . GeneratePatchFromSelection ( change , treeGuid , selection , false , tmpFile ) ;
15581564 }
15591565 else
15601566 {
1561- var tmpFile = Path . GetTempFileName ( ) ;
1562- if ( change . WorkTree == Models . ChangeState . Untracked )
1563- {
1564- diff . GenerateNewPatchFromSelection ( change , null , selection , false , tmpFile ) ;
1565- }
1566- else if ( chunk . Combined )
1567- {
1568- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1569- diff . GeneratePatchFromSelection ( change , treeGuid , selection , false , tmpFile ) ;
1570- }
1571- else
1572- {
1573- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1574- diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , false , chunk . IsOldSide , tmpFile ) ;
1575- }
1576-
1577- await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--cache --index" ) . ExecAsync ( ) ;
1578- File . Delete ( tmpFile ) ;
1567+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1568+ diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , false , chunk . IsOldSide , tmpFile ) ;
15791569 }
15801570
1571+ await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--cache --index" ) . ExecAsync ( ) ;
1572+ File . Delete ( tmpFile ) ;
1573+
15811574 repo . MarkWorkingCopyDirtyManually ( ) ;
15821575 }
15831576
@@ -1600,27 +1593,17 @@ private async void OnUnstageChunk(object _1, RoutedEventArgs _2)
16001593
16011594 using var lockWatcher = repo . LockWatcher ( ) ;
16021595
1603- if ( ! selection . HasLeftChanges )
1604- {
1605- if ( change . DataForAmend != null )
1606- await new Commands . UnstageChangesForAmend ( repo . FullPath , [ change ] ) . ExecAsync ( ) ;
1607- else
1608- await new Commands . Restore ( repo . FullPath , change ) . ExecAsync ( ) ;
1609- }
1596+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1597+ var tmpFile = Path . GetTempFileName ( ) ;
1598+ if ( change . Index == Models . ChangeState . Added )
1599+ diff . GenerateNewPatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
1600+ else if ( chunk . Combined )
1601+ diff . GeneratePatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
16101602 else
1611- {
1612- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1613- var tmpFile = Path . GetTempFileName ( ) ;
1614- if ( change . Index == Models . ChangeState . Added )
1615- diff . GenerateNewPatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
1616- else if ( chunk . Combined )
1617- diff . GeneratePatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
1618- else
1619- diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , true , chunk . IsOldSide , tmpFile ) ;
1603+ diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , true , chunk . IsOldSide , tmpFile ) ;
16201604
1621- await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--cache --index --reverse" ) . ExecAsync ( ) ;
1622- File . Delete ( tmpFile ) ;
1623- }
1605+ await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--cache --index --reverse" ) . ExecAsync ( ) ;
1606+ File . Delete ( tmpFile ) ;
16241607
16251608 repo . MarkWorkingCopyDirtyManually ( ) ;
16261609 }
@@ -1645,32 +1628,25 @@ private async void OnDiscardChunk(object _1, RoutedEventArgs _2)
16451628
16461629 using var lockWatcher = repo . LockWatcher ( ) ;
16471630
1648- if ( ! selection . HasLeftChanges )
1631+ var tmpFile = Path . GetTempFileName ( ) ;
1632+ if ( change . Index == Models . ChangeState . Added )
1633+ {
1634+ diff . GenerateNewPatchFromSelection ( change , null , selection , true , tmpFile ) ;
1635+ }
1636+ else if ( chunk . Combined )
16491637 {
1650- await Commands . Discard . ChangesAsync ( repo . FullPath , [ change ] , null ) ;
1638+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1639+ diff . GeneratePatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
16511640 }
16521641 else
16531642 {
1654- var tmpFile = Path . GetTempFileName ( ) ;
1655- if ( change . Index == Models . ChangeState . Added )
1656- {
1657- diff . GenerateNewPatchFromSelection ( change , null , selection , true , tmpFile ) ;
1658- }
1659- else if ( chunk . Combined )
1660- {
1661- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1662- diff . GeneratePatchFromSelection ( change , treeGuid , selection , true , tmpFile ) ;
1663- }
1664- else
1665- {
1666- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1667- diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , true , chunk . IsOldSide , tmpFile ) ;
1668- }
1669-
1670- await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--reverse" ) . ExecAsync ( ) ;
1671- File . Delete ( tmpFile ) ;
1643+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( repo . FullPath , change . Path ) . GetResultAsync ( ) ;
1644+ diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , true , chunk . IsOldSide , tmpFile ) ;
16721645 }
16731646
1647+ await new Commands . Apply ( repo . FullPath , tmpFile , true , "nowarn" , "--reverse" ) . ExecAsync ( ) ;
1648+ File . Delete ( tmpFile ) ;
1649+
16741650 repo . MarkWorkingCopyDirtyManually ( ) ;
16751651 }
16761652 }
0 commit comments