@@ -1709,64 +1709,65 @@ public void Stage(IEnumerable<string> paths, StageOptions stageOptions)
1709
1709
diffModifiers |= DiffModifiers . IncludeIgnored ;
1710
1710
}
1711
1711
1712
- var changes = Diff . Compare < TreeChanges > ( diffModifiers , paths , explicitPathsOptions ,
1713
- new CompareOptions { Similarity = SimilarityOptions . None } ) ;
1714
-
1715
- var unexpectedTypesOfChanges = changes
1716
- . Where (
1717
- tec => tec . Status != ChangeKind . Added &&
1718
- tec . Status != ChangeKind . Modified &&
1719
- tec . Status != ChangeKind . Conflicted &&
1720
- tec . Status != ChangeKind . Unmodified &&
1721
- tec . Status != ChangeKind . Deleted ) . ToList ( ) ;
1722
-
1723
- if ( unexpectedTypesOfChanges . Count > 0 )
1724
- {
1725
- throw new InvalidOperationException (
1726
- string . Format ( CultureInfo . InvariantCulture ,
1727
- "Entry '{0}' bears an unexpected ChangeKind '{1}'" ,
1728
- unexpectedTypesOfChanges [ 0 ] . Path , unexpectedTypesOfChanges [ 0 ] . Status ) ) ;
1729
- }
1712
+ using ( var changes = Diff . Compare < TreeChanges > ( diffModifiers , paths , explicitPathsOptions ,
1713
+ new CompareOptions { Similarity = SimilarityOptions . None } ) )
1714
+ {
1715
+ var unexpectedTypesOfChanges = changes
1716
+ . Where (
1717
+ tec => tec . Status != ChangeKind . Added &&
1718
+ tec . Status != ChangeKind . Modified &&
1719
+ tec . Status != ChangeKind . Conflicted &&
1720
+ tec . Status != ChangeKind . Unmodified &&
1721
+ tec . Status != ChangeKind . Deleted ) . ToList ( ) ;
1722
+
1723
+ if ( unexpectedTypesOfChanges . Count > 0 )
1724
+ {
1725
+ throw new InvalidOperationException (
1726
+ string . Format ( CultureInfo . InvariantCulture ,
1727
+ "Entry '{0}' bears an unexpected ChangeKind '{1}'" ,
1728
+ unexpectedTypesOfChanges [ 0 ] . Path , unexpectedTypesOfChanges [ 0 ] . Status ) ) ;
1729
+ }
1730
1730
1731
- /* Remove files from the index that don't exist on disk */
1732
- foreach ( TreeEntryChanges treeEntryChanges in changes )
1733
- {
1734
- switch ( treeEntryChanges . Status )
1731
+ /* Remove files from the index that don't exist on disk */
1732
+ foreach ( TreeEntryChanges treeEntryChanges in changes )
1735
1733
{
1736
- case ChangeKind . Conflicted :
1737
- if ( ! treeEntryChanges . Exists )
1738
- {
1734
+ switch ( treeEntryChanges . Status )
1735
+ {
1736
+ case ChangeKind . Conflicted :
1737
+ if ( ! treeEntryChanges . Exists )
1738
+ {
1739
+ RemoveFromIndex ( treeEntryChanges . Path ) ;
1740
+ }
1741
+ break ;
1742
+
1743
+ case ChangeKind . Deleted :
1739
1744
RemoveFromIndex ( treeEntryChanges . Path ) ;
1740
- }
1741
- break ;
1742
-
1743
- case ChangeKind . Deleted :
1744
- RemoveFromIndex ( treeEntryChanges . Path ) ;
1745
- break ;
1745
+ break ;
1746
1746
1747
- default :
1748
- continue ;
1747
+ default :
1748
+ continue ;
1749
+ }
1749
1750
}
1750
- }
1751
1751
1752
- foreach ( TreeEntryChanges treeEntryChanges in changes )
1753
- {
1754
- switch ( treeEntryChanges . Status )
1752
+ foreach ( TreeEntryChanges treeEntryChanges in changes )
1755
1753
{
1756
- case ChangeKind . Added :
1757
- case ChangeKind . Modified :
1758
- AddToIndex ( treeEntryChanges . Path ) ;
1759
- break ;
1760
-
1761
- case ChangeKind . Conflicted :
1762
- if ( treeEntryChanges . Exists )
1763
- {
1754
+ switch ( treeEntryChanges . Status )
1755
+ {
1756
+ case ChangeKind . Added :
1757
+ case ChangeKind . Modified :
1764
1758
AddToIndex ( treeEntryChanges . Path ) ;
1765
- }
1766
- break ;
1759
+ break ;
1760
+
1761
+ case ChangeKind . Conflicted :
1762
+ if ( treeEntryChanges . Exists )
1763
+ {
1764
+ AddToIndex ( treeEntryChanges . Path ) ;
1765
+ }
1766
+ break ;
1767
1767
1768
- default :
1769
- continue ;
1768
+ default :
1769
+ continue ;
1770
+ }
1770
1771
}
1771
1772
}
1772
1773
@@ -1802,9 +1803,10 @@ public void Unstage(IEnumerable<string> paths, ExplicitPathsOptions explicitPath
1802
1803
1803
1804
if ( Info . IsHeadUnborn )
1804
1805
{
1805
- var changes = Diff . Compare < TreeChanges > ( null , DiffTargets . Index , paths , explicitPathsOptions , new CompareOptions { Similarity = SimilarityOptions . None } ) ;
1806
-
1807
- Index . Replace ( changes ) ;
1806
+ using ( var changes = Diff . Compare < TreeChanges > ( null , DiffTargets . Index , paths , explicitPathsOptions , new CompareOptions { Similarity = SimilarityOptions . None } ) )
1807
+ {
1808
+ Index . Replace ( changes ) ;
1809
+ }
1808
1810
}
1809
1811
else
1810
1812
{
@@ -2087,48 +2089,49 @@ private void RemoveFilesAndFolders(IEnumerable<string> pathsList)
2087
2089
private IEnumerable < string > RemoveStagedItems ( IEnumerable < string > paths , bool removeFromWorkingDirectory = true , ExplicitPathsOptions explicitPathsOptions = null )
2088
2090
{
2089
2091
var removed = new List < string > ( ) ;
2090
- var changes = Diff . Compare < TreeChanges > ( DiffModifiers . IncludeUnmodified | DiffModifiers . IncludeUntracked , paths , explicitPathsOptions ) ;
2091
-
2092
- foreach ( var treeEntryChanges in changes )
2092
+ using ( var changes = Diff . Compare < TreeChanges > ( DiffModifiers . IncludeUnmodified | DiffModifiers . IncludeUntracked , paths , explicitPathsOptions ) )
2093
2093
{
2094
- var status = RetrieveStatus ( treeEntryChanges . Path ) ;
2095
-
2096
- switch ( treeEntryChanges . Status )
2094
+ foreach ( var treeEntryChanges in changes )
2097
2095
{
2098
- case ChangeKind . Added :
2099
- case ChangeKind . Deleted :
2100
- removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2101
- break ;
2102
-
2103
- case ChangeKind . Unmodified :
2104
- if ( removeFromWorkingDirectory && (
2105
- status . HasFlag ( FileStatus . ModifiedInIndex ) ||
2106
- status . HasFlag ( FileStatus . NewInIndex ) ) )
2107
- {
2108
- throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only." ,
2109
- treeEntryChanges . Path ) ;
2110
- }
2111
- removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2112
- continue ;
2113
-
2114
- case ChangeKind . Modified :
2115
- if ( status . HasFlag ( FileStatus . ModifiedInWorkdir ) && status . HasFlag ( FileStatus . ModifiedInIndex ) )
2116
- {
2117
- throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD." ,
2118
- treeEntryChanges . Path ) ;
2119
- }
2120
- if ( removeFromWorkingDirectory )
2121
- {
2122
- throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only." ,
2123
- treeEntryChanges . Path ) ;
2124
- }
2125
- removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2126
- continue ;
2096
+ var status = RetrieveStatus ( treeEntryChanges . Path ) ;
2127
2097
2128
- default :
2129
- throw new RemoveFromIndexException ( "Unable to remove file '{0}'. Its current status is '{1}'." ,
2130
- treeEntryChanges . Path ,
2131
- treeEntryChanges . Status ) ;
2098
+ switch ( treeEntryChanges . Status )
2099
+ {
2100
+ case ChangeKind . Added :
2101
+ case ChangeKind . Deleted :
2102
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2103
+ break ;
2104
+
2105
+ case ChangeKind . Unmodified :
2106
+ if ( removeFromWorkingDirectory && (
2107
+ status . HasFlag ( FileStatus . ModifiedInIndex ) ||
2108
+ status . HasFlag ( FileStatus . NewInIndex ) ) )
2109
+ {
2110
+ throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only." ,
2111
+ treeEntryChanges . Path ) ;
2112
+ }
2113
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2114
+ continue ;
2115
+
2116
+ case ChangeKind . Modified :
2117
+ if ( status . HasFlag ( FileStatus . ModifiedInWorkdir ) && status . HasFlag ( FileStatus . ModifiedInIndex ) )
2118
+ {
2119
+ throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD." ,
2120
+ treeEntryChanges . Path ) ;
2121
+ }
2122
+ if ( removeFromWorkingDirectory )
2123
+ {
2124
+ throw new RemoveFromIndexException ( "Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only." ,
2125
+ treeEntryChanges . Path ) ;
2126
+ }
2127
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
2128
+ continue ;
2129
+
2130
+ default :
2131
+ throw new RemoveFromIndexException ( "Unable to remove file '{0}'. Its current status is '{1}'." ,
2132
+ treeEntryChanges . Path ,
2133
+ treeEntryChanges . Status ) ;
2134
+ }
2132
2135
}
2133
2136
}
2134
2137
0 commit comments