@@ -345,10 +345,44 @@ public virtual void Remove(string path, bool removeFromWorkingDirectory = true,
345345 /// </param>
346346 public virtual void Remove ( IEnumerable < string > paths , bool removeFromWorkingDirectory = true , ExplicitPathsOptions explicitPathsOptions = null )
347347 {
348- var pathsList = paths . ToList ( ) ;
349- var changes = repo . Diff . Compare < TreeChanges > ( DiffModifiers . IncludeUnmodified | DiffModifiers . IncludeUntracked , pathsList , explicitPathsOptions ) ;
348+ Ensure . ArgumentNotNullOrEmptyEnumerable < string > ( paths , "paths" ) ;
350349
351- var pathsTodelete = pathsList . Where ( p => Directory . Exists ( Path . Combine ( repo . Info . WorkingDirectory , p ) ) ) . ToList ( ) ;
350+ var pathsToDelete = paths . Where ( p => Directory . Exists ( Path . Combine ( repo . Info . WorkingDirectory , p ) ) ) . ToList ( ) ;
351+ var notConflictedPaths = new List < string > ( ) ;
352+
353+ foreach ( var path in paths )
354+ {
355+ Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
356+
357+ var conflict = repo . Index . Conflicts [ path ] ;
358+
359+ if ( conflict != null )
360+ {
361+ pathsToDelete . Add ( RemoveFromIndex ( path ) ) ;
362+ }
363+ else
364+ {
365+ notConflictedPaths . Add ( path ) ;
366+ }
367+ }
368+
369+ if ( notConflictedPaths . Count > 0 )
370+ {
371+ pathsToDelete . AddRange ( RemoveStagedItems ( notConflictedPaths , removeFromWorkingDirectory , explicitPathsOptions ) ) ;
372+ }
373+
374+ if ( removeFromWorkingDirectory )
375+ {
376+ RemoveFilesAndFolders ( pathsToDelete ) ;
377+ }
378+
379+ UpdatePhysicalIndex ( ) ;
380+ }
381+
382+ private IEnumerable < string > RemoveStagedItems ( IEnumerable < string > paths , bool removeFromWorkingDirectory = true , ExplicitPathsOptions explicitPathsOptions = null )
383+ {
384+ var removed = new List < string > ( ) ;
385+ var changes = repo . Diff . Compare < TreeChanges > ( DiffModifiers . IncludeUnmodified | DiffModifiers . IncludeUntracked , paths , explicitPathsOptions ) ;
352386
353387 foreach ( var treeEntryChanges in changes )
354388 {
@@ -358,7 +392,7 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
358392 {
359393 case ChangeKind . Added :
360394 case ChangeKind . Deleted :
361- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
395+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
362396 break ;
363397
364398 case ChangeKind . Unmodified :
@@ -369,7 +403,7 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
369403 throw new RemoveFromIndexException ( string . Format ( CultureInfo . InvariantCulture , "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." ,
370404 treeEntryChanges . Path ) ) ;
371405 }
372- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
406+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
373407 continue ;
374408
375409 case ChangeKind . Modified :
@@ -383,22 +417,16 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
383417 throw new RemoveFromIndexException ( string . Format ( CultureInfo . InvariantCulture , "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." ,
384418 treeEntryChanges . Path ) ) ;
385419 }
386- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
420+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
387421 continue ;
388422
389-
390423 default :
391424 throw new RemoveFromIndexException ( string . Format ( CultureInfo . InvariantCulture , "Unable to remove file '{0}'. Its current status is '{1}'." ,
392425 treeEntryChanges . Path , treeEntryChanges . Status ) ) ;
393426 }
394427 }
395428
396- if ( removeFromWorkingDirectory )
397- {
398- RemoveFilesAndFolders ( pathsTodelete ) ;
399- }
400-
401- UpdatePhysicalIndex ( ) ;
429+ return removed ;
402430 }
403431
404432 private void RemoveFilesAndFolders ( IEnumerable < string > pathsList )
0 commit comments