@@ -345,10 +345,44 @@ public virtual void Remove(string path, bool removeFromWorkingDirectory = true,
345
345
/// </param>
346
346
public virtual void Remove ( IEnumerable < string > paths , bool removeFromWorkingDirectory = true , ExplicitPathsOptions explicitPathsOptions = null )
347
347
{
348
- var pathsList = paths . ToList ( ) ;
349
- var changes = repo . Diff . Compare < TreeChanges > ( DiffModifiers . IncludeUnmodified | DiffModifiers . IncludeUntracked , pathsList , explicitPathsOptions ) ;
348
+ Ensure . ArgumentNotNullOrEmptyEnumerable < string > ( paths , "paths" ) ;
350
349
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 ) ;
352
386
353
387
foreach ( var treeEntryChanges in changes )
354
388
{
@@ -358,7 +392,7 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
358
392
{
359
393
case ChangeKind . Added :
360
394
case ChangeKind . Deleted :
361
- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
395
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
362
396
break ;
363
397
364
398
case ChangeKind . Unmodified :
@@ -369,7 +403,7 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
369
403
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." ,
370
404
treeEntryChanges . Path ) ) ;
371
405
}
372
- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
406
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
373
407
continue ;
374
408
375
409
case ChangeKind . Modified :
@@ -383,22 +417,16 @@ public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDire
383
417
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." ,
384
418
treeEntryChanges . Path ) ) ;
385
419
}
386
- pathsTodelete . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
420
+ removed . Add ( RemoveFromIndex ( treeEntryChanges . Path ) ) ;
387
421
continue ;
388
422
389
-
390
423
default :
391
424
throw new RemoveFromIndexException ( string . Format ( CultureInfo . InvariantCulture , "Unable to remove file '{0}'. Its current status is '{1}'." ,
392
425
treeEntryChanges . Path , treeEntryChanges . Status ) ) ;
393
426
}
394
427
}
395
428
396
- if ( removeFromWorkingDirectory )
397
- {
398
- RemoveFilesAndFolders ( pathsTodelete ) ;
399
- }
400
-
401
- UpdatePhysicalIndex ( ) ;
429
+ return removed ;
402
430
}
403
431
404
432
private void RemoveFilesAndFolders ( IEnumerable < string > pathsList )
0 commit comments