Example #1
0
        public void RemoveItems(IEnumerable<SyncAction> syncActions)
        {
            syncActions = syncActions.ToList();

            if (!syncActions.Any())
            {
                return;
            }

            // make sure all to be updated actions exist (otherwise we cannot remove them)
            AssertSyncActionsExist(syncActions, true);

            using (var workingDir = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, BranchName.ToString()))
            {
                var localDirectory = new LocalDirectory(null, workingDir.Location);

                // delete the file                 
                foreach (var syncAction in syncActions)
                {
                    PathValidator.EnsureIsRootedPath(syncAction.Path);

                    var directory = localDirectory.GetDirectory(GetRelativeSyncActionDirectoryPath(syncAction));
                    var file = (ILocalFile) directory.GetFile(SyncActionFile.GetFileName(syncAction));
                    System.IO.File.Delete(file.Location);
                }

                workingDir.Commit($"{nameof(GitSyncActionService)}: Removed {syncActions.Count()} items");
                workingDir.Push();
            }
        }